Skip to content

Convert axis limit units in Qt plot options widget - #19677

Merged
jklymak merged 7 commits into
matplotlib:masterfrom
soininen:qt_figureoptions_axis_limits_conversion
May 24, 2021
Merged

jklymak merged 7 commits into
matplotlib:masterfrom
soininen:qt_figureoptions_axis_limits_conversion

Conversation

@soininen

Copy link
Copy Markdown
Contributor

PR Summary

Qt backend's plot options widget converts axis limits to floats regardless of the actual data type. If the axes use e.g. datetime values, this makes editing the axis limits next to impossible.

This tries to solve the problem at least for datetime values by converting them to a proper type that can be shown in QDateTime widget. The solution is probably not ideal as discussed in the issue but at least it helps users that regularly use datetime X axis a lot.

Resolves #19075

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

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 #19075
@jklymak

jklymak commented Mar 18, 2021

Copy link
Copy Markdown
Member

I don't use this widget, but this seems to be quite heavily leaning on special casing. Can you do something with the generic unit machinery?

@soininen

Copy link
Copy Markdown
Contributor Author

I don't use this widget, but this seems to be quite heavily leaning on special casing. Can you do something with the generic unit machinery?

This was discussed in the issue (#19075) and to my understanding there was a weak consesus of doing it this way in the absence of general unconverter. I understand the isinstance approach is not the best thing to do here. I can investigate other options but since I am not familiar with the code base any pointers would be very helpful.

@jklymak jklymak added the PR: bugfix Pull requests that fix identified bugs label May 22, 2021

@jklymak jklymak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve despite not liking the hack. I know @dstansby has been thinking about unconverters....

Comment thread lib/matplotlib/tests/test_backend_qt.py Outdated


@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
def test_form_widget_get_with_date_field():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would merge this test with the one above to avoid paying twice for the setup of the widget.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/matplotlib/tests/test_backend_qt.py Outdated
widget = _formlayout.FormWidget(form)
widget.setup()
values = widget.get()
assert(values == [datetime(year=2021, month=3, day=11)])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert needs no parentheses (it's not a function).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Thanks for the heads up!

@anntzer anntzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just two minor nits

@anntzer

anntzer commented May 24, 2021

Copy link
Copy Markdown
Contributor

anyone can merge postci

@jklymak
jklymak merged commit 8ecc571 into matplotlib:master May 24, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bugfix Pull requests that fix identified bugs topic: widgets/UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qt backend's Figure options to support axis units

4 participants