Skip to content

Commit 9d44e63

Browse files
tacaswelljreback
authored andcommitted
BUG: mpl fix to AutoDatFromatter to fix second/us-second formatters
revert part of #11770 xref: matplotlib/matplotlib#6365 closes #13131 The mistake in #11770 was missing that pandas had a 1/us not 1/s scaled bucket.
1 parent 72164a8 commit 9d44e63

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

doc/source/whatsnew/v0.18.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ Bug Fixes
141141
- Bug in ``SparseDataFrame`` in which ``axis=None`` did not default to ``axis=0`` (:issue:`13048`)
142142
- Bug in ``SparseSeries`` and ``SparseDataFrame`` creation with ``object`` dtype may raise ``TypeError`` (:issue:`11633`)
143143
- Bug when passing a not-default-indexed ``Series`` as ``xerr`` or ``yerr`` in ``.plot()`` (:issue:`11858`)
144+
- Bug in matplotlib ``AutoDataFormatter``; this restores the second scaled formatting and re-adds micro-second scaled formatting (:issue:`13131`)
144145

145146

146147
- Bug in ``.groupby(..).resample(..)`` when the same object is called multiple times (:issue:`13174`)

pandas/tseries/converter.py

+25
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
from pandas.tseries.frequencies import FreqGroup
2424
from pandas.tseries.period import Period, PeriodIndex
2525

26+
# constants
27+
HOURS_PER_DAY = 24.
28+
MIN_PER_HOUR = 60.
29+
SEC_PER_MIN = 60.
30+
31+
SEC_PER_HOUR = SEC_PER_MIN * MIN_PER_HOUR
32+
SEC_PER_DAY = SEC_PER_HOUR * HOURS_PER_DAY
33+
34+
MUSEC_PER_DAY = 1e6 * SEC_PER_DAY
35+
36+
37+
def _mpl_le_2_0_0():
38+
try:
39+
import matplotlib
40+
return matplotlib.compare_versions('2.0.0', matplotlib.__version__)
41+
except ImportError:
42+
return False
43+
2644

2745
def register():
2846
units.registry[lib.Timestamp] = DatetimeConverter()
@@ -221,6 +239,13 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
221239
if self._tz is dates.UTC:
222240
self._tz._utcoffset = self._tz.utcoffset(None)
223241

242+
# For mpl > 2.0 the format strings are controlled via rcparams
243+
# so do not mess with them. For mpl < 2.0 change the second
244+
# break point and add a musec break point
245+
if _mpl_le_2_0_0():
246+
self.scaled[1. / SEC_PER_DAY] = '%H:%M:%S'
247+
self.scaled[1. / MUSEC_PER_DAY] = '%H:%M:%S.%f'
248+
224249

225250
class PandasAutoDateLocator(dates.AutoDateLocator):
226251

0 commit comments

Comments
 (0)