-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include gridliner labels in tight bbox calculation #1355
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this looks good. I have one question, and then would you be willing to add your sample as a test?
@lukelbd did you sign the CLA? Could you rebase if so to rerun CI on this. |
@greglucas Sorry for the delay; I've signed the CLA, and can try to add a test by next weekend. |
Sounds good, @lukelbd! @dopplershift was there anything else you were requesting in addition to the test? |
@greglucas I think at this point it just needs a test. |
ping @lukelbd. |
@lukelbd we are going to try and push another beta release out this weekend. Do you think you can add the test by then, or should we look to push this back to the next 0.19 release milestone? |
Tagging the rc today, so I'm pushing this back to 0.19. |
I just ran into the case of saving a pdf and the side grid labels were partially cut off. I think this may solve that issue...? It would be good to get it into the code since it seems logical enough. |
Sorry forgot about this PR, was really busy when I was pinged. Will take a look this weekend. I think this will also need to be updated for the 0.18 gridliner API |
I added a test for the "latest everything" build only. Update 2020-07-14: The above reasoning was incorrect, but tight layout override does fail in matplotlib 1.5.0. After empirical testing, the tight layout override works only in matplotlib >=3.0. See #1575 for details. My test is similar to Here is the baseline result: And here is the result without the |
Not sure why it's failing... I built the test image by running conda config --set always_yes yes --set changeps1 no --set show_channel_urls yes
conda config --add channels conda-forge
conda config --add channels conda-forge/label/testing
conda config --set restore_free_channel true
export CYTHON_COVERAGE=1
echo "backend: agg" > ~/.matplotlib/matplotlibrc # macOS matplotlibrc
conda create -n cartopy-dev python=3.6 cython numpy matplotlib-base proj4 pykdtree scipy fiona pillow pytest pytest-xdist filelock pep8 pyshp shapely six requests pyepsg owslib pytest-cov coveralls
conda activate cartopy-dev
pip install --no-deps -e .
python -c "import cartopy; print('Version ', cartopy.__version__)" && python setup.py version
pytest |
Nevermind -- looks like the latest push fixed it! I might have accidentally generated the baseline image without the Anything else I need to do? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the image test! Overall I think this looks good. Just a few minor comments.
@greglucas Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@dopplershift I think the remaining requested change is out of date |
This PR replaces #1354.
Rationale
matplotlib.axes.Axes.get_tightbbox
fails to include cartopy gridliner labels. This is becausecartopy.mpl.gridliner.Gridliner._draw_gridliner
is not called untilAxes.draw
is invoked, which comes afterFigure.draw
invokesFigure.tight_layout
.This change adds a
get_tightbbox
override to theGeoAxes
class, which calls_draw_gridliner
on all theGridLiner
objects, so the tight layout algorithm will work. This mimics the approach used in the matplotlib API:Axes.draw
andAxes.get_tightbbox
contain many identical calls to various post-processing steps, like_update_title_position
.Implications
You can now use
fig.tight_layout()
on figures with cartopy axes containing gridliner labels.Examples
I wasn't able to install a development version of cartopy, but I implemented a virtually identical change in a
GeoAxes
subclass in my proplot package (proplot callsfig.tight_layout()
on all figures by default).Below, the first example is without the
get_tightbbox
override (there are labels present, they are just off the edge of the figure). The second example is with theget_tightbbox
override.A similar
pyplot
example could be generated by just callingfig.tight_layout()
on any cartopy plot with gridlines.