@@ -692,8 +692,10 @@ class MPLPlot(object):
692
692
"""
693
693
_default_rot = 0
694
694
695
- _pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ]
696
- _attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False }
695
+ _pop_attributes = ['label' , 'style' , 'logy' , 'logx' , 'loglog' ,
696
+ 'raise_on_error' ]
697
+ _attr_defaults = {'logy' : False , 'logx' : False , 'loglog' : False ,
698
+ 'raise_on_error' : True }
697
699
698
700
def __init__ (self , data , kind = None , by = None , subplots = False , sharex = True ,
699
701
sharey = False , use_index = True ,
@@ -1172,17 +1174,27 @@ def _make_plot(self):
1172
1174
else :
1173
1175
args = (ax , x , y , style )
1174
1176
1175
- newline = plotf (* args , ** kwds )[0 ]
1176
- lines .append (newline )
1177
- leg_label = label
1178
- if self .mark_right and self .on_right (i ):
1179
- leg_label += ' (right)'
1180
- labels .append (leg_label )
1181
- ax .grid (self .grid )
1182
-
1183
- if self ._is_datetype ():
1184
- left , right = _get_xlim (lines )
1185
- ax .set_xlim (left , right )
1177
+ try :
1178
+ newline = plotf (* args , ** kwds )[0 ]
1179
+ lines .append (newline )
1180
+ leg_label = label
1181
+ if self .mark_right and self .on_right (i ):
1182
+ leg_label += ' (right)'
1183
+ labels .append (leg_label )
1184
+ ax .grid (self .grid )
1185
+
1186
+ if self ._is_datetype ():
1187
+ left , right = _get_xlim (lines )
1188
+ ax .set_xlim (left , right )
1189
+ except AttributeError as inst : # non-numeric
1190
+ msg = ('Unable to plot data %s vs index %s,\n '
1191
+ 'error was: %s' % (str (y ), str (x ), str (inst )))
1192
+ if not self .raise_on_error :
1193
+ print msg
1194
+ else :
1195
+ msg = msg + ('\n Consider setting raise_on_error=False'
1196
+ 'to suppress' )
1197
+ raise Exception (msg )
1186
1198
1187
1199
self ._make_legend (lines , labels )
1188
1200
@@ -1200,19 +1212,32 @@ def to_leg_label(label, i):
1200
1212
return label + ' (right)'
1201
1213
return label
1202
1214
1215
+ def _plot (data , col_num , ax , label , style , ** kwds ):
1216
+ try :
1217
+ newlines = tsplot (data , plotf , ax = ax , label = label ,
1218
+ style = style , ** kwds )
1219
+ ax .grid (self .grid )
1220
+ lines .append (newlines [0 ])
1221
+ leg_label = to_leg_label (label , col_num )
1222
+ labels .append (leg_label )
1223
+ except AttributeError as inst : #non-numeric
1224
+ msg = ('Unable to plot %s,\n '
1225
+ 'error was: %s' % (str (data ), str (inst )))
1226
+ if not self .raise_on_error :
1227
+ print msg
1228
+ else :
1229
+ msg = msg + ('\n Consider setting raise_on_error=False'
1230
+ 'to suppress' )
1231
+ raise Exception (msg )
1232
+
1203
1233
if isinstance (data , Series ):
1204
1234
ax = self ._get_ax (0 ) # self.axes[0]
1205
1235
style = self .style or ''
1206
1236
label = com .pprint_thing (self .label )
1207
1237
kwds = kwargs .copy ()
1208
1238
self ._maybe_add_color (colors , kwds , style , 0 )
1209
1239
1210
- newlines = tsplot (data , plotf , ax = ax , label = label ,
1211
- style = self .style , ** kwds )
1212
- ax .grid (self .grid )
1213
- lines .append (newlines [0 ])
1214
- leg_label = to_leg_label (label , 0 )
1215
- labels .append (leg_label )
1240
+ _plot (data , 0 , ax , label , self .style , ** kwds )
1216
1241
else :
1217
1242
for i , col in enumerate (data .columns ):
1218
1243
label = com .pprint_thing (col )
@@ -1222,13 +1247,7 @@ def to_leg_label(label, i):
1222
1247
1223
1248
self ._maybe_add_color (colors , kwds , style , i )
1224
1249
1225
- newlines = tsplot (data [col ], plotf , ax = ax , label = label ,
1226
- style = style , ** kwds )
1227
-
1228
- lines .append (newlines [0 ])
1229
- leg_label = to_leg_label (label , i )
1230
- labels .append (leg_label )
1231
- ax .grid (self .grid )
1250
+ _plot (data [col ], i , ax , label , style , ** kwds )
1232
1251
1233
1252
self ._make_legend (lines , labels )
1234
1253
0 commit comments