Skip to content

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

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

Closed
soininen opened this issue Dec 7, 2020 · 3 comments · Fixed by #19677
Closed

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

soininen opened this issue Dec 7, 2020 · 3 comments · Fixed by #19677

Comments

@soininen
Copy link
Contributor

soininen commented Dec 7, 2020

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.

@anntzer
Copy link
Contributor

anntzer commented Dec 7, 2020

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.

@jklymak
Copy link
Member

jklymak commented Dec 7, 2020

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?

@soininen
Copy link
Contributor Author

soininen commented Dec 8, 2020

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?

@QuLogic QuLogic added this to the v3.5.0 milestone May 26, 2021
jklymak pushed a commit to jklymak/matplotlib that referenced this issue Jun 13, 2021
Previously axis limits were converted to floats regardless of the actual
value type in Qt backend's plot options widget. This commit makes datetime
axis limits get converted to actual datetime values which are
considerably easier to edit.

Also, the methods used to convert the datetime values back have different
names under PySide2 and PyQt. Previously the options widget was using the
methods provided by PyQt only. We now support both Qt bindings.

Re matplotlib#19075
jklymak pushed a commit to jklymak/matplotlib that referenced this issue Jun 13, 2021
jklymak pushed a commit to jklymak/matplotlib that referenced this issue Jun 13, 2021
jklymak pushed a commit to jklymak/matplotlib that referenced this issue Jun 13, 2021
jklymak pushed a commit to jklymak/matplotlib that referenced this issue Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants