-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: fig.subplots_adjust and ax.set_yticklabels together can produce unexpected results #26398
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
Setting manual tick labels does not set manual ticks. It just labels the first n ticks where n is your number of tick labels. We suggest using set_ticks with the label argument to prevent confusion |
Yes, that part is clear. In reality |
If you just want to format the labels for automatically placed ticks, you might want to set a tick formatter, rather than explicitly setting labels: |
If you adjust, you get twice as many ticks: Don't AdjustAdjustYou then label them with the un-adjuested (too few) labels: You further get a Warning
I think the warning could be less mysterious. Note that https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_xticklabels.html is discouraged in the docs. |
To summarize:
So I think our options are:
Of the options, I'm leaning towards 3. If we do just "fix it", I suspect that it can be done in a way that has 0 effect on people who were getting lucky and protect users from falling into this trap. 1 is not great (it is biting users), 2 is like the status quo but just more helpfully broken, 4 and 5 will break a bunch of users for whom things are currently "working" (and these may be low-Matplotlib-expertise users as they are using something we advise against and are currently ignoring a warning). |
I don't understand how you will "just fix it"? That's what we do now I think: There are six ticks and the user specifies four labels so two end up blank. In special cases we could infer the tick values from the strings, but that's not true in general. I started a PR to just have a specific warning in set_ticklabels that doesn't refer to mysterious classes like FixedFormatter. |
In the case where there are N ticks and the user gives us N labels, we can change what ever locator is there into a |
I believe that is what we already do. The issue here is that the number of ticks changes after the user has set the tick labels when the Axes is made larger. |
We set a |
You mean if the set_ticks happens before the resize? That could work if the order of calls is correct. I think we'd have to trigger a draw to get the ticks from the AutoLocator at that point? |
Bug summary
Setting y ticks and labels directly on an axis and then adjusting the top of the subplot of the figure can have unexpected consequences. Depending on where those ticks and labels were originally, and how the
top
ratio is set, labels will not go until the top of the y-axis, instead all the values appear with much less vertical spacing on the bottom part of the axis.Code for reproduction
Actual outcome
Expected outcome
Additional information
I suspect it depends on where those ticks and labels were originally, because we were also able to produce this bug where there was no mismatch required between labels and ticks.
It might also depend on the number of the top ratio being set.
As far as I know, adjusting other ratios (left, right, bottom, wspace, hspace) did not have an effect on this.
Operating system
Ubuntu 22.04
Matplotlib Version
3.5.1
Matplotlib Backend
agg
Python version
3.9.12
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: