Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 300bab3

Browse files
committed
Added try-except block to buffer errors from bad 'update' arguments.
(also added documentation for update)
1 parent 86bbcc5 commit 300bab3

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

plotly/plotly/plotly.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,24 @@ def iplot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options):
209209
Keyword arguments:
210210
resize (default=True) -- allow plotly to choose the figure size
211211
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
212214
213215
Additional keyword arguments:
214216
plot_options -- run help(plotly.plotly.iplot)
215217
216218
"""
217219
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
218220
if update:
219-
update_fig = tools.get_valid_graph_obj(update, 'Figure')
220-
fig.update(update_fig)
221+
try:
222+
update_fig = tools.get_valid_graph_obj(update, 'Figure')
223+
except exceptions.PlotlyGraphObjectError as err:
224+
err.add_note("Your update figure could not be properly converted "
225+
"into a plotly 'Figure' graph object.")
226+
err.prepare()
227+
raise
228+
else:
229+
fig.update(update_fig)
221230
return iplot(fig, **plot_options)
222231

223232

@@ -235,15 +244,24 @@ def plot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options):
235244
Keyword arguments:
236245
resize (default=True) -- allow plotly to choose the figure size
237246
strip_style (default=False) -- allow plotly to choose style options
247+
update (default=None) -- update the resulting figure with an 'update'
248+
dictionary-like object resembling a plotly 'Figure' object
238249
239250
Additional keyword arguments:
240251
plot_options -- run help(plotly.plotly.plot)
241252
242253
"""
243254
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
244255
if update:
245-
update_fig = tools.get_valid_graph_obj(update, 'Figure')
246-
fig.update(update_fig)
256+
try:
257+
update_fig = tools.get_valid_graph_obj(update, 'Figure')
258+
except exceptions.PlotlyGraphObjectError as err:
259+
err.add_note("Your update figure could not be properly converted "
260+
"into a plotly 'Figure' graph object.")
261+
err.prepare()
262+
raise
263+
else:
264+
fig.update(update_fig)
247265
return plot(fig, **plot_options)
248266

249267

0 commit comments

Comments
 (0)