@@ -3828,8 +3828,20 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
3828
3828
3829
3829
if kind == 'line' :
3830
3830
if use_index :
3831
- x = self .index
3831
+ if self .index .is_numeric () or self .index .is_datetime ():
3832
+ """
3833
+ Matplotlib supports numeric values or datetime objects as
3834
+ xaxis values. Taking LBYL approach here, by the time
3835
+ matplotlib raises exception when using non numeric/datetime
3836
+ values for xaxis, several actions are already taken by plt.
3837
+ """
3838
+ need_to_set_xticklabels = False
3839
+ x = self .index
3840
+ else :
3841
+ need_to_set_xticklabels = True
3842
+ x = range (len (self ))
3832
3843
else :
3844
+ need_to_set_xticklabels = False
3833
3845
x = range (len (self ))
3834
3846
3835
3847
for i , col in enumerate (_try_sort (self .columns )):
@@ -3847,6 +3859,12 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
3847
3859
3848
3860
if legend and not subplots :
3849
3861
ax .legend (loc = 'best' )
3862
+
3863
+ if need_to_set_xticklabels :
3864
+ xticklabels = [gfx ._stringify (key ) for key in self .index ]
3865
+ for ax_ in axes :
3866
+ ax_ .set_xticks (x )
3867
+ ax_ .set_xticklabels (xticklabels , rotation = rot )
3850
3868
elif kind == 'bar' :
3851
3869
self ._bar_plot (axes , subplots = subplots , grid = grid , rot = rot ,
3852
3870
legend = legend )
@@ -3865,6 +3883,8 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
3865
3883
3866
3884
def _bar_plot (self , axes , subplots = False , use_index = True , grid = True ,
3867
3885
rot = 30 , legend = True , ** kwds ):
3886
+ import pandas .tools .plotting as gfx
3887
+
3868
3888
N , K = self .shape
3869
3889
xinds = np .arange (N ) + 0.25
3870
3890
colors = 'rgbyk'
@@ -3894,7 +3914,9 @@ def _bar_plot(self, axes, subplots=False, use_index=True, grid=True,
3894
3914
fontsize = 10
3895
3915
3896
3916
ax .set_xticks (xinds + 0.25 )
3897
- ax .set_xticklabels (self .index , rotation = rot , fontsize = fontsize )
3917
+ ax .set_xticklabels ([gfx ._stringify (key ) for key in self .index ],
3918
+ rotation = rot ,
3919
+ fontsize = fontsize )
3898
3920
3899
3921
if legend and not subplots :
3900
3922
fig = ax .get_figure ()
0 commit comments