Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f3bae3

Browse files
committed
FIX and TST
1 parent 673718b commit 6f3bae3

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

lib/matplotlib/axis.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,17 +2267,15 @@ def set_inverted(self, inverted):
22672267
def set_default_intervals(self):
22682268
# docstring inherited
22692269
xmin, xmax = 0., 1.
2270-
dataMutated = self.axes.dataLim.mutatedx()
2271-
viewMutated = self.axes.viewLim.mutatedx()
2272-
if not dataMutated or not viewMutated:
2270+
# only change view if dataLim has not changed:
2271+
if not self.axes.dataLim.mutatedx():
22732272
if self.converter is not None:
22742273
info = self.converter.axisinfo(self.units, self)
22752274
if info.default_limits is not None:
22762275
valmin, valmax = info.default_limits
22772276
xmin = self.converter.convert(valmin, self.units, self)
22782277
xmax = self.converter.convert(valmax, self.units, self)
2279-
if not viewMutated:
2280-
self.axes.viewLim.intervalx = xmin, xmax
2278+
self.axes.viewLim.intervalx = xmin, xmax
22812279
self.stale = True
22822280

22832281
def get_tick_space(self):
@@ -2529,18 +2527,16 @@ def set_inverted(self, inverted):
25292527

25302528
def set_default_intervals(self):
25312529
# docstring inherited
2530+
print('Settimg y default ')
25322531
ymin, ymax = 0., 1.
2533-
dataMutated = self.axes.dataLim.mutatedy()
2534-
viewMutated = self.axes.viewLim.mutatedy()
2535-
if not dataMutated or not viewMutated:
2532+
if not self.axes.dataLim.mutatedy():
25362533
if self.converter is not None:
25372534
info = self.converter.axisinfo(self.units, self)
25382535
if info.default_limits is not None:
25392536
valmin, valmax = info.default_limits
25402537
ymin = self.converter.convert(valmin, self.units, self)
25412538
ymax = self.converter.convert(valmax, self.units, self)
2542-
if not viewMutated:
2543-
self.axes.viewLim.intervaly = ymin, ymax
2539+
self.axes.viewLim.intervaly = ymin, ymax
25442540
self.stale = True
25452541

25462542
def get_tick_space(self):

lib/matplotlib/tests/test_units.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def default_units(value, axis):
6767
return None
6868

6969
qc.convert = MagicMock(side_effect=convert)
70-
qc.axisinfo = MagicMock(side_effect=lambda u, a: munits.AxisInfo(label=u))
70+
qc.axisinfo = MagicMock(side_effect=lambda u, a:
71+
munits.AxisInfo(label=u, default_limits=(0, 100)))
7172
qc.default_units = MagicMock(side_effect=default_units)
7273
return qc
7374

@@ -219,3 +220,47 @@ def test_shared_axis_categorical():
219220
ax2.plot(d2.keys(), d2.values())
220221
ax1.xaxis.set_units(UnitData(["c", "d"]))
221222
assert "c" in ax2.xaxis.get_units()._mapping.keys()
223+
224+
225+
def test_empty_default_limits(quantity_converter):
226+
munits.registry[Quantity] = quantity_converter
227+
fig, ax1 = plt.subplots()
228+
ax1.xaxis.update_units(Quantity([10], "miles"))
229+
fig.draw_no_output()
230+
assert ax1.get_xlim() == (0, 100)
231+
ax1.yaxis.update_units(Quantity([10], "miles"))
232+
fig.draw_no_output()
233+
assert ax1.get_ylim() == (0, 100)
234+
235+
fig, ax = plt.subplots()
236+
ax.axhline(30)
237+
ax.plot(Quantity(np.arange(0, 3), "miles"),
238+
Quantity(np.arange(0, 6, 2), "feet"))
239+
fig.draw_no_output()
240+
assert ax.get_xlim() == (0, 2)
241+
assert ax.get_ylim() == (0, 30)
242+
243+
fig, ax = plt.subplots()
244+
ax.axvline(30)
245+
ax.plot(Quantity(np.arange(0, 3), "miles"),
246+
Quantity(np.arange(0, 6, 2), "feet"))
247+
fig.draw_no_output()
248+
assert ax.get_xlim() == (0, 30)
249+
assert ax.get_ylim() == (0, 4)
250+
251+
fig, ax = plt.subplots()
252+
ax.xaxis.update_units(Quantity([10], "miles"))
253+
ax.axhline(30)
254+
fig.draw_no_output()
255+
assert ax.get_xlim() == (0, 100)
256+
assert ax.get_ylim() == (28.5, 31.5)
257+
258+
fig, ax = plt.subplots()
259+
ax.yaxis.update_units(Quantity([10], "miles"))
260+
ax.axvline(30)
261+
fig.draw_no_output()
262+
assert ax.get_ylim() == (0, 100)
263+
assert ax.get_xlim() == (28.5, 31.5)
264+
265+
266+

0 commit comments

Comments
 (0)