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

Appearance settings

Commit 402e895

Browse filesBrowse files
committed
Merge pull request #3524 from cimarronm/autodatelocaltor_3522
FIX : Bug in AutoDateLocator when dates are in reverse order
2 parents cfc92e2 + 63c52f8 commit 402e895
Copy full SHA for 402e895

File tree

Expand file treeCollapse file tree

4 files changed

+28
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+28
-7
lines changed

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,10 @@ def get_locator(self, dmin, dmax):
898898
'Pick the best locator based on a distance.'
899899
delta = relativedelta(dmax, dmin)
900900

901+
# take absolute difference
902+
if dmin > dmax:
903+
delta = -delta
904+
901905
numYears = (delta.years * 1.0)
902906
numMonths = (numYears * 12.0) + delta.months
903907
numDays = (numMonths * 31.0) + delta.days
Loading

‎lib/matplotlib/tests/test_coding_standards.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_coding_standards.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
'*/matplotlib/tri/triinterpolate.py',
9797
'*/matplotlib/tests/test_axes.py',
9898
'*/matplotlib/tests/test_bbox_tight.py',
99-
'*/matplotlib/tests/test_dates.py',
10099
'*/matplotlib/tests/test_delaunay.py',
101100
'*/matplotlib/tests/test_dviread.py',
102101
'*/matplotlib/tests/test_image.py',

‎lib/matplotlib/tests/test_dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_dates.py
+24-6Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def test_DateFormatter():
162162
def test_date_formatter_callable():
163163
scale = -11
164164
locator = mock.Mock(_get_unit=mock.Mock(return_value=scale))
165-
callable_formatting_function = lambda dates, _: \
166-
[dt.strftime('%d-%m//%Y') for dt in dates]
167-
165+
callable_formatting_function = (lambda dates, _:
166+
[dt.strftime('%d-%m//%Y') for dt in dates])
167+
168168
formatter = mdates.AutoDateFormatter(locator)
169169
formatter.scaled[-10] = callable_formatting_function
170170
assert_equal(formatter([datetime.datetime(2014, 12, 25)]),
@@ -223,7 +223,8 @@ def test_auto_date_locator():
223223
def _create_auto_date_locator(date1, date2):
224224
locator = mdates.AutoDateLocator()
225225
locator.create_dummy_axis()
226-
locator.set_view_interval(mdates.date2num(date1), mdates.date2num(date2))
226+
locator.set_view_interval(mdates.date2num(date1),
227+
mdates.date2num(date2))
227228
return locator
228229

229230
d1 = datetime.datetime(1990, 1, 1)
@@ -275,8 +276,10 @@ def _create_auto_date_locator(date1, date2):
275276
'1990-01-01 00:00:40+00:00']
276277
],
277278
[datetime.timedelta(microseconds=1500),
278-
['1989-12-31 23:59:59.999507+00:00', '1990-01-01 00:00:00+00:00',
279-
'1990-01-01 00:00:00.000502+00:00', '1990-01-01 00:00:00.001005+00:00',
279+
['1989-12-31 23:59:59.999507+00:00',
280+
'1990-01-01 00:00:00+00:00',
281+
'1990-01-01 00:00:00.000502+00:00',
282+
'1990-01-01 00:00:00.001005+00:00',
280283
'1990-01-01 00:00:00.001508+00:00']
281284
],
282285
)
@@ -288,6 +291,21 @@ def _create_auto_date_locator(date1, date2):
288291
expected)
289292

290293

294+
@image_comparison(baseline_images=['date_inverted_limit'],
295+
extensions=['png'])
296+
def test_date_inverted_limit():
297+
# test ax hline with date inputs
298+
t0 = datetime.datetime(2009, 1, 20)
299+
tf = datetime.datetime(2009, 1, 31)
300+
fig = plt.figure()
301+
ax = fig.add_subplot(1, 1, 1)
302+
ax.axhline(t0, color="blue", lw=3)
303+
ax.set_ylim(t0 - datetime.timedelta(days=5),
304+
tf + datetime.timedelta(days=5))
305+
ax.invert_yaxis()
306+
fig.subplots_adjust(left=0.25)
307+
308+
291309
if __name__ == '__main__':
292310
import nose
293311
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.