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
Fix FixedFormatter #4302
Fix FixedFormatter #4302
Conversation
hmm, dug a bit deeper into the |
@WeatherGod: How so? |
Because the default formatter is ScalarFormatter, but after explicitly setting the tick labels, it becomes a FixedFormatter:
|
So, the position is assumed to be an index into the sequence, but the data coordinate system isn't necessarially set up that way, I think. |
ah, it is even easier than that! |
return '' | ||
else: | ||
return self.seq[pos] | ||
return self.seq[int(np.round(x)] |
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.
syntax error. Missing parens.
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.
This breaks the use case where you do
from matplotlib.ticker import FixedLocator, FixedFormatter
fig, ax = plt.subplots()
ax.xaxis.set_major_locator(FixedLocator([10, 20, 30]))
ax.xaxis.set_major_formatter(FixedFormatter(['a', 'b', 'c']))
ax.set_xlim([5, 35])
ah, and I took a look at your changes and I see you arrived at the same spot in the code in a different way. So, what was "pos" ever for? |
I came across this a while ago and thought it was a feature not a bug ;). If you are using a fixed formatter, then you have de-coupled the tick labels from the data so there is no sensible way we can guess at what the values between the ticks are. I think |
See https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axis.py#L873 for where the formatter is called as part of the |
Ah, of course. If the labels are not 1-to-1 with values this isn't going to work. Thanks. |
In investigating #4301, I discovered that when you set explicit tick labels, the value display in the toolbar doesn't work. Strangely, it seems to have been this way at least since 1.1 (before that, I can't compile due to libpng API changes).
To reproduce:
Looking at the FixedFormatter code, it seems that it's supposed to be keying the values from a kwarg
pos
, but I can't see anywhere in the code wherepos
is being passed...Does this change make sense? I think probably not, but it's broken as it stands in any event...
Cc: @efiring