Skip to content

Commit 5d7fb08

Browse files
author
Chang She
committed
BUG: put mpl unit registry back in for set_xlim
1 parent 3a0c265 commit 5d7fb08

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

pandas/tools/plotting.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
from pandas.tseries.frequencies import get_period_alias, get_base_alias
1717
from pandas.tseries.offsets import DateOffset
1818

19-
"""
2019
try: # mpl optional
2120
import pandas.tseries.converter as conv
22-
conv.register()
21+
conv.register() # needs to override so set_xlim works with str/number
2322
except ImportError:
2423
pass
25-
"""
2624

2725
def _get_standard_kind(kind):
2826
return {'density': 'kde'}.get(kind, kind)
@@ -913,20 +911,6 @@ def _maybe_add_color(self, colors, kwds, style, i):
913911
if style is None or re.match('[a-z]+', style) is None:
914912
kwds['color'] = colors[i % len(colors)]
915913

916-
def _make_formatter_locator(self):
917-
import pandas.tseries.converter as conv
918-
index = self.data.index
919-
if (isinstance(index, DatetimeIndex) or
920-
index.inferred_type in ('datetime', 'datetime64', 'date')):
921-
tz = getattr(index, 'tz', None)
922-
loc = conv.PandasAutoDateLocator(tz=tz)
923-
fmt = conv.PandasAutoDateFormatter(loc, tz=tz)
924-
return fmt, loc
925-
if index.inferred_type == 'time':
926-
loc = conv.AutoLocator()
927-
fmt = conv.TimeFormatter(loc)
928-
return fmt, loc
929-
930914
def _make_plot(self):
931915
import pandas.tseries.plotting as tsplot
932916
# this is slightly deceptive
@@ -969,9 +953,7 @@ def _make_plot(self):
969953
ax.grid(self.grid)
970954

971955
if self._is_datetype():
972-
_maybe_format_dateaxis(ax, *self._make_formatter_locator())
973956
left, right = _get_xlim(lines)
974-
print 'xlim: ', left, right
975957
ax.set_xlim(left, right)
976958

977959
self._make_legend(lines, labels)
@@ -1937,22 +1919,22 @@ def on_right(i):
19371919

19381920
return fig, axes
19391921

1940-
def _maybe_format_dateaxis(ax, formatter, locator):
1941-
from matplotlib import pylab
1942-
ax.xaxis.set_major_locator(locator)
1943-
ax.xaxis.set_major_formatter(formatter)
1944-
pylab.draw_if_interactive()
1945-
1946-
19471922
def _get_xlim(lines):
19481923
import pandas.tseries.converter as conv
19491924
left, right = np.inf, -np.inf
19501925
for l in lines:
19511926
x = l.get_xdata()
1952-
left = min(conv._dt_to_float_ordinal(x[0]), left)
1953-
right = max(conv._dt_to_float_ordinal(x[-1]), right)
1927+
left = min(_maybe_convert_date(x[0]), left)
1928+
right = max(_maybe_convert_date(x[-1]), right)
19541929
return left, right
19551930

1931+
def _maybe_convert_date(x):
1932+
if not com.is_integer(x):
1933+
conv_func = conv._dt_to_float_ordinal
1934+
if isinstance(x, datetime.time):
1935+
conv_func = conv._to_ordinalf
1936+
x = conv_func(x)
1937+
return x
19561938

19571939
if __name__ == '__main__':
19581940
# import pandas.rpy.common as com

pandas/tseries/converter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
def register():
2525
units.registry[lib.Timestamp] = DatetimeConverter()
2626
units.registry[Period] = PeriodConverter()
27+
units.registry[pydt.datetime] = DatetimeConverter()
28+
units.registry[pydt.date] = DatetimeConverter()
29+
units.registry[pydt.time] = TimeConverter()
2730

2831
def _to_ordinalf(tm):
2932
tot_sec = (tm.hour * 3600 + tm.minute * 60 + tm.second +

0 commit comments

Comments
 (0)