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

Commit78dda48

Browse files
committed
Apply un_convert to ginput(), get_xlim(), set_xlim()
1 parent185e95b commit78dda48

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

‎lib/matplotlib/axes/_base.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,16 @@ def get_xlim(self):
30413041
be greater than the `right` value.
30423042
30433043
"""
3044-
returntuple(self.viewLim.intervalx)
3044+
returnself._convert_back_lim(self.viewLim.intervalx,self.xaxis)
3045+
3046+
def_convert_back_lim(self,lim,axis):
3047+
"""
3048+
Helper method to convert axis limits back to unitized data.
3049+
"""
3050+
ifaxis.converterisnotNone:
3051+
lim= [axis.converter.un_convert(l,axis.units,axis)for
3052+
linlim]
3053+
returntuple(lim)
30453054

30463055
def_validate_converted_limits(self,limit,convert):
30473056
"""
@@ -3393,6 +3402,7 @@ def get_ylim(self):
33933402
will be greater than the `top` value.
33943403
33953404
"""
3405+
returnself._convert_back_lim(self.viewLim.intervaly,self.yaxis)
33963406
returntuple(self.viewLim.intervaly)
33973407

33983408
defset_ylim(self,bottom=None,top=None,emit=True,auto=False,

‎lib/matplotlib/axis.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,11 @@ def convert_units(self, x):
15371537
ret=self.converter.convert(x,self.units,self)
15381538
returnret
15391539

1540+
defunconvert_units(self,x):
1541+
ifself.converterisNone:
1542+
returnx
1543+
returnself.converter.un_convert(x,self.units,self)
1544+
15401545
defset_units(self,u):
15411546
"""
15421547
Set the units for axis.

‎lib/matplotlib/blocking_input.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@ def mouse_event_pop(self, event):
180180

181181
defadd_click(self,event):
182182
"""Add the coordinates of an event to the list of clicks."""
183-
self.clicks.append((event.xdata,event.ydata))
183+
x=event.inaxes.xaxis.unconvert_units(event.xdata)
184+
y=event.inaxes.yaxis.unconvert_units(event.ydata)
185+
self.clicks.append((x,y))
184186
_log.info("input %i: %f, %f",
185-
len(self.clicks),event.xdata,event.ydata)
187+
len(self.clicks),x,y)
186188
# If desired, plot up click.
187189
ifself.show_clicks:
188-
line=mlines.Line2D([event.xdata], [event.ydata],
190+
line=mlines.Line2D([x], [y],
189191
marker='+',color='r')
190192
event.inaxes.add_line(line)
191193
self.marks.append(line)

‎lib/matplotlib/tests/test_axes.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,3 +5815,14 @@ class DummySubplot(matplotlib.axes.SubplotBase, Dummy):
58155815
FactoryDummySubplot=matplotlib.axes.subplot_class_factory(Dummy)
58165816

58175817
assertDummySubplotisFactoryDummySubplot
5818+
5819+
5820+
deftest_lim_units():
5821+
# Check that get_(x,y)lim() returns unitized data
5822+
fig,ax=plt.subplots()
5823+
ax.scatter([datetime.datetime(2000,1,1)],
5824+
[datetime.datetime(2000,1,1)])
5825+
xlim=ax.get_xlim()
5826+
ylim=ax.get_ylim()
5827+
forlinxlim+ylim:
5828+
asserttype(l)isdatetime.datetime

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp