FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Docs: Units example broken · Issue #5051 · matplotlib/matplotlib · GitHub

Repository navigation

Docs: Units example broken #5051

Closed

Description

http://matplotlib.org/examples/units/units_scatter.html

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.

Activity

  1. WeatherGod commented on Sep 11, 2015

    Member

    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:

    http://matplotlib.org/examples/units/units_scatter.html

    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.

  2. hamogu commented on Sep 11, 2015

    ContributorAuthor

    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.

  3. efiring commented on May 23, 2019

    Member

    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.

  4. efiring commented on May 23, 2019

    Member

    @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.

  5. dopplershift commented on May 24, 2019

    Contributor

    Ooh, a chance to fix a 4-digit issue...

  6. 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.

  7. l-johnston commented on Aug 24, 2020

    Contributor

    @dopplershift This example is broken for at least two reasons.

    1. 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.
    2. 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:

    def __array__(self, dtype=object):
            # return np.asarray(self.value).astype(dtype)
            return np.asarray([TaggedValue(v, self.unit) for v in self.value])

    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.

  8. jklymak commented on Jul 9, 2021

    Member

    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.

  9. removed
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Aug 18, 2022
  10. added this to the needs sorting milestone on Aug 18, 2022
  11. ksunden commented on Mar 20, 2023

    Member

    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).

  12. added a commit that references this issue on Mar 20, 2023
    88ed2c8
  13. added 4 commits that reference this issue on Apr 19, 2026
    631d8d2
    5073d3b
    7f4b092
    51b94e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL