Skip to content

Commit f89ced4

Browse files
author
Chang She
committed
BUG: incorrect tick label positions #1531 (zooming is still wrong)
1 parent 1475971 commit f89ced4

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pandas/tools/plotting.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,12 @@ def _adorn_subplots(self):
461461
self.ax.set_title(self.title)
462462

463463
if self._need_to_set_index:
464-
xticklabels = [_stringify(key) for key in self.data.index]
464+
labels = [_stringify(key) for key in self.data.index]
465+
labels = dict(zip(range(len(self.data.index)), labels))
466+
465467
for ax_ in self.axes:
466468
# ax_.set_xticks(self.xticks)
469+
xticklabels = [labels.get(x, '') for x in ax_.get_xticks()]
467470
ax_.set_xticklabels(xticklabels, rotation=self.rot)
468471

469472
@property
@@ -575,7 +578,7 @@ def _post_plot_logic(self):
575578
if self.subplots and self.legend:
576579
self.axes[0].legend(loc='best')
577580

578-
try:
581+
try: # matplotlib is optional dependency
579582
import matplotlib.units as units
580583
import matplotlib.dates as dates
581584

@@ -663,6 +666,7 @@ def _make_plot(self):
663666
if mask.any():
664667
y = np.ma.array(y)
665668
y = np.ma.masked_where(mask, y)
669+
666670
plotf(ax, x, y, style, label=label, **self.kwds)
667671
ax.grid(self.grid)
668672

pandas/tseries/tests/test_plotting.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ def test_from_weekly_resampling(self):
561561

562562
@slow
563563
def test_irreg_dtypes(self):
564+
import matplotlib.pyplot as plt
564565
#date
565566
idx = [date(2000, 1, 1), date(2000, 1, 5), date(2000, 1, 20)]
566567
df = DataFrame(np.random.randn(len(idx), 3), Index(idx, dtype=object))
@@ -573,10 +574,16 @@ def test_irreg_dtypes(self):
573574
_check_plot_works(df.plot)
574575

575576
#time
576-
inc = Series(np.random.randint(1, 6, 9)).cumsum().values
577+
plt.close('all')
578+
inc = Series(np.random.randint(1, 15, 3)).cumsum().values
577579
idx = [time(1, 1, i) for i in inc]
578580
df = DataFrame(np.random.randn(len(idx), 3), idx)
579-
_check_plot_works(df.plot)
581+
ax = df.plot()
582+
ticks = ax.get_xticks()
583+
labels = ax.get_xticklabels()
584+
td = dict(zip(ticks, labels))
585+
for i in range(3):
586+
self.assert_(td[i].get_text() == str(idx[i]))
580587

581588
PNG_PATH = 'tmp.png'
582589
def _check_plot_works(f, freq=None, series=None, *args, **kwargs):

0 commit comments

Comments
 (0)