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

Skip to content

Commit c9852c6

Browse files
committed
Changed how errors work for iplot/plot_mpl(fig, update=update)
1 parent 300bab3 commit c9852c6

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

plotly/plotly/plotly.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,19 @@ def iplot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options):
217217
218218
"""
219219
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
220-
if update:
220+
if update and isinstance(update, dict):
221221
try:
222-
update_fig = tools.get_valid_graph_obj(update, 'Figure')
222+
fig.update(update)
223+
fig.validate()
223224
except exceptions.PlotlyGraphObjectError as err:
224-
err.add_note("Your update figure could not be properly converted "
225-
"into a plotly 'Figure' graph object.")
225+
err.add_note("Your updated figure could not be properly validated.")
226226
err.prepare()
227227
raise
228-
else:
229-
fig.update(update_fig)
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+
)
230233
return iplot(fig, **plot_options)
231234

232235

@@ -252,16 +255,19 @@ def plot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options):
252255
253256
"""
254257
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
255-
if update:
258+
if update and isinstance(update, dict):
256259
try:
257-
update_fig = tools.get_valid_graph_obj(update, 'Figure')
260+
fig.update(update)
261+
fig.validate()
258262
except exceptions.PlotlyGraphObjectError as err:
259-
err.add_note("Your update figure could not be properly converted "
260-
"into a plotly 'Figure' graph object.")
263+
err.add_note("Your updated figure could not be properly validated.")
261264
err.prepare()
262265
raise
263-
else:
264-
fig.update(update_fig)
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+
)
265271
return plot(fig, **plot_options)
266272

267273

0 commit comments

Comments
 (0)