-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Inconsistent y-axis unit label with plot/scatter #23416
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
I'm not sure which way we should go with this. Pandas and xarray and maybe others autolabel when plot is called. But you almost always have to modify the labels to have actual name of the variable so utility of stating the units seems margins to me. Given that the units don't work properly under change of units I would consider just removing this feature of plot |
Given the current MPL behaviour is to label axes, I think this inconsistency should be fixed to show the label, and changing this behaviour more widely is orthogonal to this bug. |
😨 This shows me I understand little of the unit handling. FeatureI agree with @jklymak that adding a unit label is of questionable value. Furthermore, the current behavior is quite obscure:
ConsistencyWe definitely should make this consistent. Given (3) it's RecommendationI strongly suggest to deprecate showing the label and get over this magic mess. At our core we want to be a simple understandable library with which you can configure your plot step by step. Note in particular that we do not auto-label |
I broadly agree with the above comment, but again would say that a long term plan for this labelling is orthogonal to this issue, which is about fixing a specific bug and making the labelling consistent whether |
The thing is that the consistency fix (=adding the label in more cases) is going in the opposite direction of the long-term plan (not having the label at all). |
I think the further point is that plot is the outlier here. none of the other plotting methods label axes (that I know of) |
I'm pretty sure this is incorrect - I just checked and it works for from basic_units import cm
import matplotlib.pyplot as plt
import numpy as np
cms = cm * np.arange(0, 10, 2)
fig, axs = plt.subplots(1, 4, tight_layout=True)
axs[0].stem(np.arange(5), cms)
axs[1].bar(np.arange(5), cms)
axs[2].scatter(np.arange(5), cms)
axs[3].fill_between(np.arange(5), cms)
plt.show() |
Interesting. OTOH does it work with pcolormesh or contour? (Sorry away from computer) |
Yep, works with both |
Well, then I agree it should be consistent... Sorry for not checking... |
Sorry for letting this slip. I'll have a look again and respond soonish. |
Oh, the issue is not that |
This fix ended up breaking pandas so we reverted, re-opening this issues and moving to 3.8 |
Further discussion is available at #25219 as to how the original fix affected pandas. (just linking here a bit more explicitly) |
Bug summary
When manually setting the units of an axis using
set_units
, aplot
will show an axis label, but ascatter
won't.The example needs to be run in
examples/units
to have access to thebasic_units.py
file.Code for reproduction
Actual outcome
Expected outcome
When the units aren't explicitly set (commenting out

set_units()
), the output is as expected with both labels:Additional information
No response
Operating system
No response
Matplotlib Version
3.6.0.dev2669+gdc163ca442.d20220712
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
git checkout
The text was updated successfully, but these errors were encountered: