-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Order of ax.spines[].set_position() and ax.yaxis.set_major_formatter() produces different results #2941
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
The major formatter is definitely not getting propagated through the
However I am not sure what the 'correct' behavior is. |
My understanding was basically that unless two calls were mutually exclusive (e.g., the same parameter getting set twice) all commands prior to If this is the design goal, it seems this should propagate through changing the position of the spines. Users would expect spine position and formatting of the axis label to be independent. |
@JDWarner duh, yes, you are right. Looking at this again I was confused about what was going on (thought that the non-commuting operation was setting the ticks to be on the right axis, not the left, which is not what is happening). Re-milestoned and labeled accordingly. |
Digging into this, it seems the offending line (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/spines.py#L382) clear the axis (which resets everything to the defaults) after adjusting the spine position. This looks like it was a feature of the original introduction of this code in 2009 (43ca13b) ! I suspect the fix is to just remove the |
I don't think this is a bug per se, just a wart. I don't remember exactly why the call to By design, the matplotlib API is not order-independent. For example, this code shows that most basic plotting commands get drawn in the order they were called:
|
@astraw Granted, as I noted before when one or more command either references the same space or is mutually exclusive the order matters. Ergo the The behavior in this issue, however, is not mutually exclusive nor is it intuitive to the user. When setting independent (or seemingly independent) features about a figure/axis, it's not expected that the order would matter. |
Clearing the axis is excessive; calling axis.reset_ticks() seems to be both necessary and sufficient. Closes matplotlib#2941
In the first example,
ax.spines['right'].set_position()
is called first, and the negative signs on the right y-axis are smaller hyphen-minus symbols because they were passed throughax.yaxis.set_major_formatter()
. in the second example, the order is reversed, and the formatter is not applied or is reset (i.e., the negative signs are the larger unicode character\u2212
).I was under the impression that matplotlib settings were order-agnostic before
plt.show()
- is this a bug?The text was updated successfully, but these errors were encountered: