Skip to content
Browse files

BUG: incorrect tick label positions #1531 (zooming is still wrong)

  • Loading branch information...
1 parent 1475971 commit f89ced44269746125a06482d8947bde12fa373bc Chang She committed Jun 26, 2012
Showing with 15 additions and 4 deletions.
  1. +6 −2 pandas/tools/plotting.py
  2. +9 −2 pandas/tseries/tests/test_plotting.py
View
8 pandas/tools/plotting.py
@@ -461,9 +461,12 @@ def _adorn_subplots(self):
self.ax.set_title(self.title)
if self._need_to_set_index:
- xticklabels = [_stringify(key) for key in self.data.index]
+ labels = [_stringify(key) for key in self.data.index]
+ labels = dict(zip(range(len(self.data.index)), labels))
+
for ax_ in self.axes:
# ax_.set_xticks(self.xticks)
+ xticklabels = [labels.get(x, '') for x in ax_.get_xticks()]
ax_.set_xticklabels(xticklabels, rotation=self.rot)
@property
@@ -575,7 +578,7 @@ def _post_plot_logic(self):
if self.subplots and self.legend:
self.axes[0].legend(loc='best')
-try:
+try: # matplotlib is optional dependency
import matplotlib.units as units
import matplotlib.dates as dates
@@ -663,6 +666,7 @@ def _make_plot(self):
if mask.any():
y = np.ma.array(y)
y = np.ma.masked_where(mask, y)
+
plotf(ax, x, y, style, label=label, **self.kwds)
ax.grid(self.grid)
View
11 pandas/tseries/tests/test_plotting.py
@@ -561,6 +561,7 @@ def test_from_weekly_resampling(self):
@slow
def test_irreg_dtypes(self):
+ import matplotlib.pyplot as plt
#date
idx = [date(2000, 1, 1), date(2000, 1, 5), date(2000, 1, 20)]
df = DataFrame(np.random.randn(len(idx), 3), Index(idx, dtype=object))
@@ -573,10 +574,16 @@ def test_irreg_dtypes(self):
_check_plot_works(df.plot)
#time
- inc = Series(np.random.randint(1, 6, 9)).cumsum().values
+ plt.close('all')
+ inc = Series(np.random.randint(1, 15, 3)).cumsum().values
idx = [time(1, 1, i) for i in inc]
df = DataFrame(np.random.randn(len(idx), 3), idx)
- _check_plot_works(df.plot)
+ ax = df.plot()
+ ticks = ax.get_xticks()
+ labels = ax.get_xticklabels()
+ td = dict(zip(ticks, labels))
+ for i in range(3):
+ self.assert_(td[i].get_text() == str(idx[i]))
PNG_PATH = 'tmp.png'
def _check_plot_works(f, freq=None, series=None, *args, **kwargs):

0 comments on commit f89ced4

Please sign in to comment.
Something went wrong with that request. Please try again.