shows how to use units and automatic scaling. Looking at the image, plot 2 and 3 look identical, although ax3.yaxis.set_units(minutes) should set the scale of the third plot to minutes. Apparently, the command changes the tick labels, but does not rescale the data.
shows how to use units and automatic scaling. Looking at the image, plot 2
and 3 look identical, although ax3.yaxis.set_units(minutes) should set
the scale of the third plot to minutes. Apparently, the command changes the
tick labels, but does not rescale the data.
—
Reply to this email directly or view it on GitHub #5051.
That's what I thought at first. I even started a PR to fix that (but did not upload it). Then I realized that there is the line
ax3.yaxis.set_units(minutes)
So presumably, this ax3 should show the following: We plot with unit Hertz, but then we reset the unit to minutes and the plot changes to adjust that.
Except, that the plot does not change and adjust to it, so it just looks stupid.
This is embarrassing. We've had a blatantly nonsensical example sitting around for years. Minimal fix: delete the third subplot. Better fix: figure out how to make the third subplot show something useful, perhaps via fixing the code in basic_units.py.
@dopplershift, you are the units expert, right? I know you are not responsible for this example, but maybe you can figure out what to do with it. Or just rip it all out, if it is hopeless.
I could put in a quick fix for this that looks like this example
I looked a little at the underlying problem (that set_units is missing some code to rescale after changing the label) and tried adding some calls to try to get the axis to rescale. I couldn't get it to work. If anyone has idea/suggestions, I could look into it. I'm too new to the codebase to figure this one out on my own though, I think.
@dopplershift This example is broken for at least two reasons.
Very early in plotting functions Axes calls cbook._check_1d on the data that then calls np.atleast_1d that strips basic_units.TaggedValue of its units.
scatter doesn't support Axes.set_units because Axes.relim doesn't support Collections.
TaggedValue defines __array__ which is numpy's dispatch mechanism. It is possible to modify it to return an array of TaggedValue objects:
The original issue with units_scatter appears to have been fixed insofar as the example being correct by #12422, before much of the conversation here, so I'm slightly confused.
That said, the issue with the bar chart example does appear to persist (and I think as well with changing units on scatter, but not plot, after plotting).
Activity
WeatherGod commented on Sep 11, 2015
Actually, I think the problem is that the third plot has yunits=hertz...
that doesn't seem to make any sense whatever.
On Fri, Sep 11, 2015 at 2:48 PM, Hans Moritz Günther <
notifications@github.com> wrote:
hamogu commented on Sep 11, 2015
That's what I thought at first. I even started a PR to fix that (but did not upload it). Then I realized that there is the line
So presumably, this ax3 should show the following: We plot with unit Hertz, but then we reset the unit to minutes and the plot changes to adjust that.
Except, that the plot does not change and adjust to it, so it just looks stupid.
efiring commented on May 23, 2019
This is embarrassing. We've had a blatantly nonsensical example sitting around for years. Minimal fix: delete the third subplot. Better fix: figure out how to make the third subplot show something useful, perhaps via fixing the code in basic_units.py.
efiring commented on May 23, 2019
@dopplershift, you are the units expert, right? I know you are not responsible for this example, but maybe you can figure out what to do with it. Or just rip it all out, if it is hopeless.
dopplershift commented on May 24, 2019
Ooh, a chance to fix a 4-digit issue...
stevenjlm commented on Jan 16, 2020
I could put in a quick fix for this that looks like this example
I looked a little at the underlying problem (that set_units is missing some code to rescale after changing the label) and tried adding some calls to try to get the axis to rescale. I couldn't get it to work. If anyone has idea/suggestions, I could look into it. I'm too new to the codebase to figure this one out on my own though, I think.
l-johnston commented on Aug 24, 2020
@dopplershift This example is broken for at least two reasons.
TaggedValue defines __array__ which is numpy's dispatch mechanism. It is possible to modify it to return an array of TaggedValue objects:
This will allow some plotting functions, like plot, to work. But, scatter is still broken due to reason 2. I recommend deleting units_scatter.py.
jklymak commented on Jul 9, 2021
https://matplotlib.org/stable/gallery/units/bar_unit_demo.html is also broken - bars are provided in centimetres, but then the units are converted to inches, but the numbers don't change.
ksunden commented on Mar 20, 2023
The original issue with units_scatter appears to have been fixed insofar as the example being correct by #12422, before much of the conversation here, so I'm slightly confused.
That said, the issue with the bar chart example does appear to persist (and I think as well with changing units on scatter, but not plot, after plotting).
DOC: Fix the bars having numeric value of cm but labeled as inches
DOC: Fix the bars having numeric value of cm but labeled as inches
DOC: Fix the bars having numeric value of cm but labeled as inches
DOC: Fix the bars having numeric value of cm but labeled as inches
DOC: Fix the bars having numeric value of cm but labeled as inches