Skip to content

Commit

Permalink
Merge pull request #3524 from cimarronm/autodatelocaltor_3522
Browse files Browse the repository at this point in the history
FIX : Bug in AutoDateLocator when dates are in reverse order
  • Loading branch information
tacaswell committed Sep 19, 2014
2 parents cfc92e2 + 63c52f8 commit 402e895
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/matplotlib/dates.py
Expand Up @@ -898,6 +898,10 @@ def get_locator(self, dmin, dmax):
'Pick the best locator based on a distance.'
delta = relativedelta(dmax, dmin)

# take absolute difference
if dmin > dmax:
delta = -delta

numYears = (delta.years * 1.0)
numMonths = (numYears * 12.0) + delta.months
numDays = (numMonths * 31.0) + delta.days
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_coding_standards.py
Expand Up @@ -96,7 +96,6 @@
'*/matplotlib/tri/triinterpolate.py',
'*/matplotlib/tests/test_axes.py',
'*/matplotlib/tests/test_bbox_tight.py',
'*/matplotlib/tests/test_dates.py',
'*/matplotlib/tests/test_delaunay.py',
'*/matplotlib/tests/test_dviread.py',
'*/matplotlib/tests/test_image.py',
Expand Down
30 changes: 24 additions & 6 deletions lib/matplotlib/tests/test_dates.py
Expand Up @@ -162,9 +162,9 @@ def test_DateFormatter():
def test_date_formatter_callable():
scale = -11
locator = mock.Mock(_get_unit=mock.Mock(return_value=scale))
callable_formatting_function = lambda dates, _: \
[dt.strftime('%d-%m//%Y') for dt in dates]
callable_formatting_function = (lambda dates, _:
[dt.strftime('%d-%m//%Y') for dt in dates])

formatter = mdates.AutoDateFormatter(locator)
formatter.scaled[-10] = callable_formatting_function
assert_equal(formatter([datetime.datetime(2014, 12, 25)]),
Expand Down Expand Up @@ -223,7 +223,8 @@ def test_auto_date_locator():
def _create_auto_date_locator(date1, date2):
locator = mdates.AutoDateLocator()
locator.create_dummy_axis()
locator.set_view_interval(mdates.date2num(date1), mdates.date2num(date2))
locator.set_view_interval(mdates.date2num(date1),
mdates.date2num(date2))
return locator

d1 = datetime.datetime(1990, 1, 1)
Expand Down Expand Up @@ -275,8 +276,10 @@ def _create_auto_date_locator(date1, date2):
'1990-01-01 00:00:40+00:00']
],
[datetime.timedelta(microseconds=1500),
['1989-12-31 23:59:59.999507+00:00', '1990-01-01 00:00:00+00:00',
'1990-01-01 00:00:00.000502+00:00', '1990-01-01 00:00:00.001005+00:00',
['1989-12-31 23:59:59.999507+00:00',
'1990-01-01 00:00:00+00:00',
'1990-01-01 00:00:00.000502+00:00',
'1990-01-01 00:00:00.001005+00:00',
'1990-01-01 00:00:00.001508+00:00']
],
)
Expand All @@ -288,6 +291,21 @@ def _create_auto_date_locator(date1, date2):
expected)


@image_comparison(baseline_images=['date_inverted_limit'],
extensions=['png'])
def test_date_inverted_limit():
# test ax hline with date inputs
t0 = datetime.datetime(2009, 1, 20)
tf = datetime.datetime(2009, 1, 31)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.axhline(t0, color="blue", lw=3)
ax.set_ylim(t0 - datetime.timedelta(days=5),
tf + datetime.timedelta(days=5))
ax.invert_yaxis()
fig.subplots_adjust(left=0.25)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 comments on commit 402e895

Please sign in to comment.