@@ -1624,9 +1624,10 @@ def __init__(self, base=1, month=1, day=1, tz=None):
16241624 'minute' : 0 ,
16251625 'second' : 0 ,
16261626 }
1627- # Note that tzinfo does not work with pytz timezones, and
1628- # astimezone doesn't work unless a datetime has timezone info (for
1629- # py3.5). So the user should provide time-zone aware dates.
1627+ if not hasattr (tz , 'localize' ):
1628+ # if tz is pytz, we need to do this w/ the localize fcn,
1629+ # otherwise datetime.replace works fine...
1630+ self .replaced ['tzinfo' ] = tz
16301631
16311632 def __call__ (self ):
16321633 # if no data have been set, this will tank with a ValueError
@@ -1642,17 +1643,24 @@ def tick_values(self, vmin, vmax):
16421643 ymax = self .base .ge (vmax .year ) * self .base .step
16431644
16441645 vmin = vmin .replace (year = ymin , ** self .replaced )
1645- try :
1646- ticks = [vmin .astimezone (self .tz )]
1647- except ValueError as e :
1648- raise ValueError ('naive datetime objects cannot be used '
1649- 'with matplotlib for python < 3.6; ' ) from e
1646+ if hasattr (self .tz , 'localize' ):
1647+ # look after pytz
1648+ if not vmin .tzinfo :
1649+ vmin = self .tz .localize (vmin , is_dst = True )
1650+
1651+ ticks = [vmin ]
1652+
16501653 while True :
16511654 dt = ticks [- 1 ]
16521655 if dt .year >= ymax :
16531656 return date2num (ticks )
16541657 year = dt .year + self .base .step
1655- dt = dt .replace (year = year , ** self .replaced ).astimezone (self .tz )
1658+ dt = dt .replace (year = year , ** self .replaced )
1659+ if hasattr (self .tz , 'localize' ):
1660+ # look after pytz
1661+ if not dt .tzinfo :
1662+ dt = self .tz .localize (dt , is_dst = True )
1663+
16561664 ticks .append (dt )
16571665
16581666 def autoscale (self ):
0 commit comments