1
1
# being a bit too dynamic
2
2
# pylint: disable=E1101
3
- from itertools import izip
4
3
import datetime
5
4
import warnings
6
5
import re
@@ -701,10 +700,8 @@ class MPLPlot(object):
701
700
"""
702
701
_default_rot = 0
703
702
704
- _pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ,
705
- 'raise_on_error' ]
706
- _attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False ,
707
- 'raise_on_error' : True }
703
+ _pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ]
704
+ _attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False }
708
705
709
706
def __init__ (self , data , kind = None , by = None , subplots = False , sharex = True ,
710
707
sharey = False , use_index = True ,
@@ -875,7 +872,27 @@ def _get_layout(self):
875
872
return (len (self .data .columns ), 1 )
876
873
877
874
def _compute_plot_data (self ):
878
- pass
875
+ try :
876
+ # might be a frame
877
+ numeric_data = self .data ._get_numeric_data ()
878
+ except AttributeError :
879
+ # a series, but no object dtypes allowed!
880
+ if self .data .dtype == np .object_ :
881
+ raise TypeError ('invalid dtype for plotting, please cast to a '
882
+ 'numeric dtype explicitly if you want to plot' )
883
+
884
+ numeric_data = self .data
885
+
886
+ try :
887
+ is_empty = numeric_data .empty
888
+ except AttributeError :
889
+ is_empty = not len (numeric_data )
890
+
891
+ # no empty frames or series allowed
892
+ if is_empty :
893
+ raise TypeError ('No numeric data to plot' )
894
+
895
+ self .data = numeric_data
879
896
880
897
def _make_plot (self ):
881
898
raise NotImplementedError
@@ -1184,27 +1201,17 @@ def _make_plot(self):
1184
1201
else :
1185
1202
args = (ax , x , y , style )
1186
1203
1187
- try :
1188
- newline = plotf (* args , ** kwds )[0 ]
1189
- lines .append (newline )
1190
- leg_label = label
1191
- if self .mark_right and self .on_right (i ):
1192
- leg_label += ' (right)'
1193
- labels .append (leg_label )
1194
- ax .grid (self .grid )
1195
-
1196
- if self ._is_datetype ():
1197
- left , right = _get_xlim (lines )
1198
- ax .set_xlim (left , right )
1199
- except AttributeError as inst : # non-numeric
1200
- msg = ('Unable to plot data %s vs index %s,\n '
1201
- 'error was: %s' % (str (y ), str (x ), str (inst )))
1202
- if not self .raise_on_error :
1203
- print msg
1204
- else :
1205
- msg = msg + ('\n Consider setting raise_on_error=False'
1206
- 'to suppress' )
1207
- raise Exception (msg )
1204
+ newline = plotf (* args , ** kwds )[0 ]
1205
+ lines .append (newline )
1206
+ leg_label = label
1207
+ if self .mark_right and self .on_right (i ):
1208
+ leg_label += ' (right)'
1209
+ labels .append (leg_label )
1210
+ ax .grid (self .grid )
1211
+
1212
+ if self ._is_datetype ():
1213
+ left , right = _get_xlim (lines )
1214
+ ax .set_xlim (left , right )
1208
1215
1209
1216
self ._make_legend (lines , labels )
1210
1217
@@ -1223,22 +1230,12 @@ def to_leg_label(label, i):
1223
1230
return label
1224
1231
1225
1232
def _plot (data , col_num , ax , label , style , ** kwds ):
1226
- try :
1227
- newlines = tsplot (data , plotf , ax = ax , label = label ,
1228
- style = style , ** kwds )
1229
- ax .grid (self .grid )
1230
- lines .append (newlines [0 ])
1231
- leg_label = to_leg_label (label , col_num )
1232
- labels .append (leg_label )
1233
- except AttributeError as inst : #non-numeric
1234
- msg = ('Unable to plot %s,\n '
1235
- 'error was: %s' % (str (data ), str (inst )))
1236
- if not self .raise_on_error :
1237
- print msg
1238
- else :
1239
- msg = msg + ('\n Consider setting raise_on_error=False'
1240
- 'to suppress' )
1241
- raise Exception (msg )
1233
+ newlines = tsplot (data , plotf , ax = ax , label = label ,
1234
+ style = style , ** kwds )
1235
+ ax .grid (self .grid )
1236
+ lines .append (newlines [0 ])
1237
+ leg_label = to_leg_label (label , col_num )
1238
+ labels .append (leg_label )
1242
1239
1243
1240
if isinstance (data , Series ):
1244
1241
ax = self ._get_ax (0 ) # self.axes[0]
@@ -1610,8 +1607,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
1610
1607
If not passed, uses gca()
1611
1608
style : string, default matplotlib default
1612
1609
matplotlib line style to use
1613
- grid : matplot grid
1614
- legend: matplot legende
1610
+ grid : matplotlib grid
1611
+ legend: matplotlib legend
1615
1612
logx : boolean, default False
1616
1613
For line plots, use log scaling on x axis
1617
1614
logy : boolean, default False
@@ -1633,6 +1630,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
1633
1630
klass = BarPlot
1634
1631
elif kind == 'kde' :
1635
1632
klass = KdePlot
1633
+ else :
1634
+ raise ValueError ('Invalid chart type given %s' % kind )
1636
1635
1637
1636
"""
1638
1637
If no axis is specified, we check whether there are existing figures.
0 commit comments