Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert axis limit units in Qt plot options widget#19677

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 7 commits intomatplotlib:masterfromsoininen:qt_figureoptions_axis_limits_conversion
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletionslib/matplotlib/backends/qt_editor/_formlayout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -342,9 +342,17 @@ def get(self):
elif isinstance(value, Real):
value = float(str(field.text()))
elif isinstance(value, datetime.datetime):
value = field.dateTime().toPyDateTime()
datetime_ = field.dateTime()
if hasattr(datetime_, "toPyDateTime"):
value = datetime_.toPyDateTime()
else:
value = datetime_.toPython()
elif isinstance(value, datetime.date):
value = field.date().toPyDate()
date_ = field.date()
if hasattr(date_, "toPyDate"):
value = date_.toPyDate()
else:
value = date_.toPython()
else:
value = eval(str(field.text()))
valuelist.append(value)
Expand Down
18 changes: 12 additions & 6 deletionslib/matplotlib/backends/qt_editor/figureoptions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,7 @@
from matplotlib import cbook, cm, colors as mcolors, markers, image as mimage
from matplotlib.backends.qt_compat import QtGui
from matplotlib.backends.qt_editor import _formlayout

from matplotlib.dates import DateConverter, num2date

LINESTYLES = {'-': 'Solid',
'--': 'Dashed',
Expand All@@ -33,9 +33,17 @@ def figure_edit(axes, parent=None):
sep = (None, None) # separator

# Get / General
# Cast to builtin floats as they have nicer reprs.
xmin, xmax = map(float, axes.get_xlim())
ymin, ymax = map(float, axes.get_ylim())
def convert_limits(lim, converter):
"""Convert axis limits for correct input editors."""
if isinstance(converter, DateConverter):
return map(num2date, lim)
# Cast to builtin floats as they have nicer reprs.
return map(float, lim)

xconverter = axes.xaxis.converter
xmin, xmax = convert_limits(axes.get_xlim(), xconverter)
yconverter = axes.yaxis.converter
ymin, ymax = convert_limits(axes.get_ylim(), yconverter)
general = [('Title', axes.get_title()),
sep,
(None, "<b>X-Axis</b>"),
Expand All@@ -52,8 +60,6 @@ def figure_edit(axes, parent=None):
]

# Save the unit data
xconverter = axes.xaxis.converter
yconverter = axes.yaxis.converter
xunits = axes.xaxis.get_units()
yunits = axes.yaxis.get_units()

Expand Down
40 changes: 39 additions & 1 deletionlib/matplotlib/tests/test_backend_qt.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import copy
from datetime import date, datetime
import signal
from unittest import mock

Expand All@@ -10,7 +11,8 @@


try:
from matplotlib.backends.qt_compat import QtGui
from matplotlib.backends.qt_compat import QtGui, QtWidgets
from matplotlib.backends.qt_editor import _formlayout
except ImportError:
pytestmark = pytest.mark.skip('No usable Qt5 bindings')

Expand DownExpand Up@@ -258,6 +260,20 @@ def test_figureoptions():
fig.canvas.manager.toolbar.edit_parameters()


@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
def test_figureoptions_with_datetime_axes():
fig, ax = plt.subplots()
xydata = [
datetime(year=2021, month=1, day=1),
datetime(year=2021, month=2, day=1)
]
ax.plot(xydata, xydata)
with mock.patch(
"matplotlib.backends.qt_editor._formlayout.FormDialog.exec_",
lambda self: None):
fig.canvas.manager.toolbar.edit_parameters()


@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
def test_double_resize():
# Check that resizing a figure twice keeps the same window size
Expand DownExpand Up@@ -295,3 +311,25 @@ def crashing_callback(fig, stale):
canvas = FigureCanvasQTAgg(fig)
fig.stale = True
assert called


@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
def test_form_widget_get_with_datetime_field():
if not QtWidgets.QApplication.instance():
QtWidgets.QApplication()
form = [("Field name", datetime(year=2021, month=3, day=11))]
widget = _formlayout.FormWidget(form)
widget.setup()
values = widget.get()
assert(values == [datetime(year=2021, month=3, day=11)])
Copy link
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
ContributorAuthor

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!



@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
def test_form_widget_get_with_date_field():
Copy link
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
ContributorAuthor

Choose a reason for hiding this comment

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

Done.

if not QtWidgets.QApplication.instance():
QtWidgets.QApplication()
form = [("Field name", date(year=2021, month=3, day=11))]
widget = _formlayout.FormWidget(form)
widget.setup()
values = widget.get()
assert(values == [date(year=2021, month=3, day=11)])

[8]ページ先頭

©2009-2025 Movatter.jp