Skip to content

Commit 8d45dc4

Browse files
committed
ENH: let users disable autoconversion to PeriodIndex in plotting so an externally setup twinx can work with irregular + regular freq timeseries #2205
1 parent 5d5bda6 commit 8d45dc4

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pandas 0.9.1
5656
- Make .drop(...) work with non-unique indexes (#2101)
5757
- Improve performance of Series/DataFrame.diff (re: #2087)
5858
- Support unary ~ (__invert__) in DataFrame (#2110)
59+
- Turn off pandas-style tick locators and formatters (#2205)
5960

6061
**Bug fixes**
6162

doc/source/v0.9.1.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ New features
6060
parse_cols='A:D')
6161

6262

63+
- Added option to disable pandas-style tick locators and formatters
64+
using `series.plot(x_compat=True)` or `pandas.plot_params['x_compat'] =
65+
True` (GH2205_)
6366
- Existing TimeSeries methods `at_time` and `between_time` were added to
6467
DataFrame (GH2149_)
6568
- DataFrame.dot can now accept ndarrays (GH2042_)
@@ -122,6 +125,7 @@ on GitHub for a complete list.
122125
.. _GH2124: https://github.com/pydata/pandas/issues/2124
123126
.. _GH2110: https://github.com/pydata/pandas/issues/2110
124127
.. _GH2184: https://github.com/pydata/pandas/issues/2184
128+
.. _GH2205: https://github.com/pydata/pandas/issues/2205
125129

126130
.. _GH2181: https://github.com/pydata/pandas/issues/2181
127131
.. _GH2180: https://github.com/pydata/pandas/issues/2180
@@ -197,4 +201,3 @@ on GitHub for a complete list.
197201
.. _GH1959: https://github.com/pydata/pandas/issues/1959
198202
.. _GH1890: https://github.com/pydata/pandas/issues/1890
199203
.. _GH1555: https://github.com/pydata/pandas/issues/1555
200-

pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
from pandas.tools.describe import value_range
3737
from pandas.tools.merge import merge, concat, ordered_merge
3838
from pandas.tools.pivot import pivot_table, crosstab
39-
from pandas.tools.plotting import scatter_matrix
39+
from pandas.tools.plotting import scatter_matrix, plot_params
4040
from pandas.tools.tile import cut, qcut

pandas/tests/test_graphics.py

+22
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,28 @@ def test_plot_xy(self):
233233
# columns.inferred_type == 'mixed'
234234
# TODO add MultiIndex test
235235

236+
@slow
237+
def test_xcompat(self):
238+
import pandas as pd
239+
import matplotlib.pyplot as plt
240+
241+
df = tm.makeTimeDataFrame()
242+
ax = df.plot(x_compat=True)
243+
lines = ax.get_lines()
244+
self.assert_(not isinstance(lines[0].get_xdata(), PeriodIndex))
245+
246+
plt.close('all')
247+
pd.plot_params['xaxis.compat'] = True
248+
ax = df.plot()
249+
lines = ax.get_lines()
250+
self.assert_(not isinstance(lines[0].get_xdata(), PeriodIndex))
251+
252+
plt.close('all')
253+
pd.plot_params['x_compat'] = False
254+
ax = df.plot()
255+
lines = ax.get_lines()
256+
self.assert_(isinstance(lines[0].get_xdata(), PeriodIndex))
257+
236258
def _check_data(self, xp, rs):
237259
xp_lines = xp.get_lines()
238260
rs_lines = rs.get_lines()

pandas/tools/plotting.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,43 @@ def _get_standard_kind(kind):
2626
return {'density': 'kde'}.get(kind, kind)
2727

2828

29+
class _Options(dict):
30+
31+
#alias so the names are same as plotting method parameter names
32+
_ALIASES = {'x_compat' : 'xaxis.compat'}
33+
_DEFAULT_KEYS = ['xaxis.compat']
34+
35+
def __init__(self):
36+
self['xaxis.compat'] = False
37+
38+
def __getitem__(self, key):
39+
key = self._get_canonical_key(key)
40+
if key not in self:
41+
raise ValueError('%s is not a valid pandas plotting option' % key)
42+
return super(_Options, self).__getitem__(key)
43+
44+
def __setitem__(self, key, value):
45+
key = self._get_canonical_key(key)
46+
return super(_Options, self).__setitem__(key, value)
47+
48+
def __delitem__(self, key):
49+
key = self._get_canonical_key(key)
50+
if key in self._DEFAULT_KEYS:
51+
raise ValueError('Cannot remove default parameter %s' % key)
52+
return super(_Options, self).__delitem__(key)
53+
54+
def __contains__(self, key):
55+
key = self._get_canonical_key(key)
56+
return super(_Options, self).__contains__(key)
57+
58+
def reset(self):
59+
self.__init__()
60+
61+
def _get_canonical_key(self, key):
62+
return self._ALIASES.get(key, key)
63+
64+
plot_params = _Options()
65+
2966
def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
3067
diagonal='hist', marker='.', **kwds):
3168
"""
@@ -875,6 +912,9 @@ class LinePlot(MPLPlot):
875912
def __init__(self, data, **kwargs):
876913
self.mark_right = kwargs.pop('mark_right', True)
877914
MPLPlot.__init__(self, data, **kwargs)
915+
self.x_compat = plot_params['x_compat']
916+
if 'x_compat' in self.kwds:
917+
self.x_compat = bool(self.kwds.pop('x_compat'))
878918

879919
def _index_freq(self):
880920
from pandas.core.frame import DataFrame
@@ -923,7 +963,7 @@ def _maybe_add_color(self, colors, kwds, style, i):
923963
def _make_plot(self):
924964
import pandas.tseries.plotting as tsplot
925965
# this is slightly deceptive
926-
if self.use_index and self._use_dynamic_x():
966+
if not self.x_compat and self.use_index and self._use_dynamic_x():
927967
data = self._maybe_convert_index(self.data)
928968
self._make_ts_plot(data, **self.kwds)
929969
else:

0 commit comments

Comments
 (0)