Skip to content

Commit 8a34d46

Browse files
committed
Merge pull request #3648 from elpres/patch-1
FIX: dates.YearLocator doesn't handle inverted axes
2 parents 786eb8c + 9783e24 commit 8a34d46

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/matplotlib/dates.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,16 @@ def set_tzinfo(self, tz):
698698

699699
def datalim_to_dt(self):
700700
dmin, dmax = self.axis.get_data_interval()
701+
if dmin > dmax:
702+
dmin, dmax = dmax, dmin
703+
701704
return num2date(dmin, self.tz), num2date(dmax, self.tz)
702705

703706
def viewlim_to_dt(self):
704707
vmin, vmax = self.axis.get_view_interval()
708+
if vmin > vmax:
709+
vmin, vmax = vmax, vmin
710+
705711
return num2date(vmin, self.tz), num2date(vmax, self.tz)
706712

707713
def _get_unit(self):
@@ -748,8 +754,6 @@ def __call__(self):
748754
return self.tick_values(dmin, dmax)
749755

750756
def tick_values(self, vmin, vmax):
751-
if vmin > vmax:
752-
vmax, vmin = vmin, vmax
753757
delta = relativedelta(vmax, vmin)
754758

755759
# We need to cap at the endpoints of valid datetime
@@ -820,9 +824,6 @@ def autoscale(self):
820824
Set the view limits to include the data range.
821825
"""
822826
dmin, dmax = self.datalim_to_dt()
823-
if dmin > dmax:
824-
dmax, dmin = dmin, dmax
825-
826827
delta = relativedelta(dmax, dmin)
827828

828829
# We need to cap at the endpoints of valid datetime

0 commit comments

Comments
 (0)