@@ -195,7 +195,7 @@ def plot(figure_or_data, validate=True, **plot_options):
195
195
raise exceptions .PlotlyAccountError (res ['error' ])
196
196
197
197
198
- def iplot_mpl (fig , resize = True , strip_style = False , ** plot_options ):
198
+ def iplot_mpl (fig , resize = True , strip_style = False , update = None , ** plot_options ):
199
199
"""Replot a matplotlib figure with plotly in IPython.
200
200
201
201
This function:
@@ -209,16 +209,31 @@ def iplot_mpl(fig, resize=True, strip_style=False, **plot_options):
209
209
Keyword arguments:
210
210
resize (default=True) -- allow plotly to choose the figure size
211
211
strip_style (default=False) -- allow plotly to choose style options
212
+ update (default=None) -- update the resulting figure with an 'update'
213
+ dictionary-like object resembling a plotly 'Figure' object
212
214
213
215
Additional keyword arguments:
214
216
plot_options -- run help(plotly.plotly.iplot)
215
217
216
218
"""
217
219
fig = tools .mpl_to_plotly (fig , resize = resize , strip_style = strip_style )
220
+ if update and isinstance (update , dict ):
221
+ try :
222
+ fig .update (update )
223
+ fig .validate ()
224
+ except exceptions .PlotlyGraphObjectError as err :
225
+ err .add_note ("Your updated figure could not be properly validated." )
226
+ err .prepare ()
227
+ raise
228
+ elif update :
229
+ raise exceptions .PlotlyGraphObjectError (
230
+ "'update' must be dictionary-like and a valid plotly Figure "
231
+ "object. Run 'help(plotly.graph_objs.Figure)' for more info."
232
+ )
218
233
return iplot (fig , ** plot_options )
219
234
220
235
221
- def plot_mpl (fig , resize = True , strip_style = False , ** plot_options ):
236
+ def plot_mpl (fig , resize = True , strip_style = False , update = None , ** plot_options ):
222
237
"""Replot a matplotlib figure with plotly.
223
238
224
239
This function:
@@ -232,12 +247,27 @@ def plot_mpl(fig, resize=True, strip_style=False, **plot_options):
232
247
Keyword arguments:
233
248
resize (default=True) -- allow plotly to choose the figure size
234
249
strip_style (default=False) -- allow plotly to choose style options
250
+ update (default=None) -- update the resulting figure with an 'update'
251
+ dictionary-like object resembling a plotly 'Figure' object
235
252
236
253
Additional keyword arguments:
237
254
plot_options -- run help(plotly.plotly.plot)
238
255
239
256
"""
240
257
fig = tools .mpl_to_plotly (fig , resize = resize , strip_style = strip_style )
258
+ if update and isinstance (update , dict ):
259
+ try :
260
+ fig .update (update )
261
+ fig .validate ()
262
+ except exceptions .PlotlyGraphObjectError as err :
263
+ err .add_note ("Your updated figure could not be properly validated." )
264
+ err .prepare ()
265
+ raise
266
+ elif update :
267
+ raise exceptions .PlotlyGraphObjectError (
268
+ "'update' must be dictionary-like and a valid plotly Figure "
269
+ "object. Run 'help(plotly.graph_objs.Figure)' for more info."
270
+ )
241
271
return plot (fig , ** plot_options )
242
272
243
273
0 commit comments