@@ -2961,8 +2961,8 @@ def clip_lower(self, threshold):
2961
2961
#----------------------------------------------------------------------
2962
2962
# Plotting
2963
2963
2964
- def plot (self , subplots = False , sharex = True , sharey = False , use_index = True ,
2965
- figsize = None , grid = True , legend = True , ax = None , ** kwds ):
2964
+ def plot (self , kind = 'line' , subplots = False , sharex = True , sharey = False , use_index = True ,
2965
+ figsize = None , grid = True , legend = True , rot = 30 , ax = None , ** kwds ):
2966
2966
"""
2967
2967
Make line plot of DataFrame's series with the index on the x-axis using
2968
2968
matplotlib / pylab.
@@ -2998,22 +2998,49 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
2998
2998
else :
2999
2999
fig = ax .get_figure ()
3000
3000
3001
- if use_index :
3002
- x = self .index
3003
- else :
3004
- x = range (len (self ))
3001
+ if kind == 'line' :
3002
+ if use_index :
3003
+ x = self .index
3004
+ else :
3005
+ x = range (len (self ))
3006
+
3007
+ for i , col in enumerate (_try_sort (self .columns )):
3008
+ empty = self [col ].count () == 0
3009
+ y = self [col ].values if not empty else np .zeros (x .shape )
3010
+ if subplots :
3011
+ ax = axes [i ]
3012
+ ax .plot (x , y , 'k' , label = str (col ), ** kwds )
3013
+ ax .legend (loc = 'best' )
3014
+ else :
3015
+ ax .plot (x , y , label = str (col ), ** kwds )
3016
+
3017
+ ax .grid (grid )
3018
+ elif kind == 'bar' :
3019
+ N = len (self )
3020
+ M = len (self .columns )
3021
+ xinds = np .arange (N ) + 0.25
3022
+ colors = ['red' , 'green' , 'blue' , 'yellow' , 'black' ]
3023
+ rects = []
3024
+ labels = []
3025
+ for i , col in enumerate (_try_sort (self .columns )):
3026
+ empty = self [col ].count () == 0
3027
+ y = self [col ].values if not empty else np .zeros (x .shape )
3028
+ if subplots :
3029
+ ax = axes [i ]
3030
+ ax .bar (xinds , y , 0.5 ,
3031
+ bottom = np .zeros (N ), linewidth = 1 , ** kwds )
3032
+ ax .set_title (col )
3033
+ else :
3034
+ rects .append (ax .bar (xinds + i * 0.5 / M ,y ,0.5 / M ,bottom = np .zeros (N ),color = colors [i % len (colors )], ** kwds ))
3035
+ labels .append (col )
3005
3036
3006
- for i , col in enumerate (_try_sort (self .columns )):
3007
- empty = self [col ].count () == 0
3008
- y = self [col ].values if not empty else np .zeros (x .shape )
3009
- if subplots :
3010
- ax = axes [i ]
3011
- ax .plot (x , y , 'k' , label = str (col ), ** kwds )
3012
- ax .legend (loc = 'best' )
3037
+ if N < 10 :
3038
+ fontsize = 12
3013
3039
else :
3014
- ax . plot ( x , y , label = str ( col ), ** kwds )
3040
+ fontsize = 10
3015
3041
3016
- ax .grid (grid )
3042
+ ax .set_xticks (xinds + 0.25 )
3043
+ ax .set_xticklabels (self .index , rotation = rot , fontsize = fontsize )
3017
3044
3018
3045
# try to make things prettier
3019
3046
try :
@@ -3022,7 +3049,10 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
3022
3049
pass
3023
3050
3024
3051
if legend and not subplots :
3025
- ax .legend (loc = 'best' )
3052
+ if kind == 'line' :
3053
+ ax .legend (loc = 'best' )
3054
+ else :
3055
+ ax .legend ([r [0 ] for r in rects ],labels ,loc = 'best' )
3026
3056
3027
3057
plt .draw_if_interactive ()
3028
3058
0 commit comments