-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
tight_layout reserves tick space even if disabled #11203
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
Comments
Workarounds To save a plot with no margins around you may leave out the
or
But it is interesting that the undesired behaviour seems to be due to the ticks. So an option is indeed to let the (turned off) ticks point inwards by adding
This also works fine with the rest of the code from the OP. Problem I don't think this has anything to do with the legend being part of the tight layout. Given that the tick direction is responsible for this behaviour I would guess that it has been there all the time, but only shows up now that the ticks point outwards by default. I don't have any 1.x version available right now, but you may try to set
in your 1.5 version and see if that reproduces the undesired behaviour. |
Yeah this isn’t an issue to do w the legend changes. @ImportanceOfBeingErnest is correct that it’s due to the tick direction change in 2.0 |
Thank you very much for your suggestion @ImportanceOfBeingErnest, that does the trick for me! Re older version: I tried your code to draw the ticks on the outside, that doesn't result in the same behaviour. Instead: I think my issue may be related to #10361 which would also overlap with the versions that show and don't show this behaviour. edit: @jklymak that can't be the only reason as I don't have the same behaviour in 1.5.3 just by drawing the ticks on the outside. |
I'd argue the current behaviour is correct - the tight bounding box should include the ticks. If 1.5.3 didn't do that, I guess there was a behaviour change, but in my opinion it was for the better. |
Yes the tight box needs to include the ticks for sure. But should it include axes decorators which are not drawn at all; e.g. the ticks when Pro the current behaviour: You get reproducible plots, independent on whether the axis is turned on or off. |
Sorry I missed the axis off part. That indeed seems to be a bug |
I think #11210 fixes the problem. I do think it was an unintended bug when outward ticks started being the default, but visibility was overlooked. |
Bug report
tight_layout seems to reserve space for axes ticks even if they are removed
I like to save a plot with zero surrounding whitespace.
Previously (version 1.5.3) this was possible by setting
bbox_inches='tight', pad_inches=0
in thesavefig
call and removing any axis decorators (ticks, labels). In the current version (version 2.2.2) the whitespace around the plot cannot be fully removed in the above way, even if decorators are removed. It seems that the remaining whitespace corresponds to the area that the axis ticks would be drawn in, had they not been removed.This seems to be related to recent changes in how axes legends get drawn:
It seems not possible to save a plot with no surrounding whitespace in the current version.
Code for reproduction
Actual outcome (using matplotlib 2.2.2)

test_ticks.png
:image dimensions: 239 * 232 pixels
test_noticks.png
:image dimensions: 239 * 232 pixels
Expected outcome (using matplotlib 1.5.3)

test_ticks.png
:image dimensions: 232 * 232 pixels
(drawing the ticks inside the plot is obviously not desirable as well but I think this illustrates the difference in behaviour)
test_noticks.png
:image dimensions: 232 * 232 pixels
(this is what I'd like to get with the above code).
Matplotlib version
print(matplotlib.get_backend())
):module://ipykernel.pylab.backend_inline
(also tried in Qt5Agg)All throught conda default channel, the code example was run in two separate virtual environments, one downgraded to matplotlib 1.5.3.
The text was updated successfully, but these errors were encountered: