Skip to content

Qt backend's Figure options to support axis units #19075

Closed

Description

@soininen

Problem

We often use datetimes on X axis. However, Qt backend's figure options dialog converts these to floating point numbers making it all but possible to edit the axis xmin and xmax.

Proposed Solution

Make the options dialog deal with axis units more properly, e.g. datetimes could be shown using QDateTimeEdit widget.

I managed to get this working for datetimes and X axis on a monkey-patched options dialog by replacing line 37 in matploglib/backends/qt_editor by

    if isinstance(axes.xaxis.converter, DateConverter):
        xmin, xmax = tuple(num2date(lim) for lim in axes.get_xlim())
    else:
        xmin, xmax = map(float, axes.get_xlim())

Would this be an acceptable way of dealing with the units in general? I would be willing to work on a Pull request on this.

Activity

  1. anntzer commented on Dec 7, 2020

    @anntzer
    Contributor

    That seems reasonable (in the absence of having a way to get unitized limits back, but I guess that's not going to happen until we have a general unconverter (#12270, #16922)).
    Note that I'd guess the patch at #18958 (comment) would still be needed to support PySide2, though.

  2. jklymak commented on Dec 7, 2020

    @jklymak
    Member

    Right, thats a reasonable hack for one converter, but not for units in general. I'd be mildly against having a bunch of special casing of dates, but maybe its worth the pain?

  3. soininen commented on Dec 8, 2020

    @soininen
    ContributorAuthor

    I cannot say I am fully happy with the isinstance() solution myself so I am all ears if there is a better way to do this. Maybe this could work as a stopgap solution until something like a general unconverted gets implemented, though?

  4. added this to the v3.5.0 milestone on May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions