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

Skip to content

Commit 673718b

Browse files
committed
FIX: empty data assymetry
1 parent c56e3c5 commit 673718b

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lib/matplotlib/axis.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,8 +2276,6 @@ def set_default_intervals(self):
22762276
valmin, valmax = info.default_limits
22772277
xmin = self.converter.convert(valmin, self.units, self)
22782278
xmax = self.converter.convert(valmax, self.units, self)
2279-
if not dataMutated:
2280-
self.axes.dataLim.intervalx = xmin, xmax
22812279
if not viewMutated:
22822280
self.axes.viewLim.intervalx = xmin, xmax
22832281
self.stale = True
@@ -2541,8 +2539,6 @@ def set_default_intervals(self):
25412539
valmin, valmax = info.default_limits
25422540
ymin = self.converter.convert(valmin, self.units, self)
25432541
ymax = self.converter.convert(valmax, self.units, self)
2544-
if not dataMutated:
2545-
self.axes.dataLim.intervaly = ymin, ymax
25462542
if not viewMutated:
25472543
self.axes.viewLim.intervaly = ymin, ymax
25482544
self.stale = True
Binary file not shown.

lib/matplotlib/tests/test_dates.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,55 @@ def test_date2num_NaT_scalar(units):
7070
assert np.isnan(tmpl)
7171

7272

73-
@image_comparison(['date_empty.png'])
7473
def test_date_empty():
7574
# make sure we do the right thing when told to plot dates even
7675
# if no date data has been presented, cf
7776
# http://sourceforge.net/tracker/?func=detail&aid=2850075&group_id=80706&atid=560720
7877
fig, ax = plt.subplots()
7978
ax.xaxis_date()
79+
fig.draw_no_output()
80+
np.testing.assert_allclose(ax.get_xlim(),
81+
[mdates.date2num(np.datetime64('2000-01-01')),
82+
mdates.date2num(np.datetime64('2010-01-01'))])
8083

84+
mdates._reset_epoch_test_example()
85+
mdates.set_epoch('0000-12-31')
86+
fig, ax = plt.subplots()
87+
ax.xaxis_date()
88+
fig.draw_no_output()
89+
np.testing.assert_allclose(ax.get_xlim(),
90+
[mdates.date2num(np.datetime64('2000-01-01')),
91+
mdates.date2num(np.datetime64('2010-01-01'))])
92+
mdates._reset_epoch_test_example()
93+
94+
95+
def test_date_not_empty():
96+
fig = plt.figure()
97+
ax = fig.add_subplot()
98+
99+
ax.plot([50, 70], [1, 2])
100+
ax.xaxis.axis_date()
101+
np.testing.assert_allclose(ax.get_xlim(), [50, 70])
102+
103+
104+
def test_axhline():
105+
# make sure that axhline doesn't set the xlimits...
106+
fig, ax = plt.subplots()
107+
ax.axhline(1.5)
108+
ax.plot([np.datetime64('2016-01-01'), np.datetime64('2016-01-02')], [1, 2])
109+
np.testing.assert_allclose(ax.get_xlim(),
110+
[mdates.date2num(np.datetime64('2016-01-01')),
111+
mdates.date2num(np.datetime64('2016-01-02'))])
112+
113+
mdates._reset_epoch_test_example()
114+
mdates.set_epoch('0000-12-31')
115+
fig, ax = plt.subplots()
116+
ax.axhline(1.5)
117+
ax.plot([np.datetime64('2016-01-01'), np.datetime64('2016-01-02')], [1, 2])
118+
np.testing.assert_allclose(ax.get_xlim(),
119+
[mdates.date2num(np.datetime64('2016-01-01')),
120+
mdates.date2num(np.datetime64('2016-01-02'))])
121+
mdates._reset_epoch_test_example()
81122

82123
@image_comparison(['date_axhspan.png'])
83124
def test_date_axhspan():

0 commit comments

Comments
 (0)