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

Skip to content

Commit acc68a1

Browse files
committed
Merge pull request plotly#31 from plotly/mpl-updated
Mpl updated
2 parents 7b71be9 + c9852c6 commit acc68a1

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

plotly/plotly/plotly.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def plot(figure_or_data, validate=True, **plot_options):
195195
raise exceptions.PlotlyAccountError(res['error'])
196196

197197

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):
199199
"""Replot a matplotlib figure with plotly in IPython.
200200
201201
This function:
@@ -209,16 +209,31 @@ def iplot_mpl(fig, resize=True, strip_style=False, **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)
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+
)
218233
return iplot(fig, **plot_options)
219234

220235

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):
222237
"""Replot a matplotlib figure with plotly.
223238
224239
This function:
@@ -232,12 +247,27 @@ def plot_mpl(fig, resize=True, strip_style=False, **plot_options):
232247
Keyword arguments:
233248
resize (default=True) -- allow plotly to choose the figure size
234249
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
235252
236253
Additional keyword arguments:
237254
plot_options -- run help(plotly.plotly.plot)
238255
239256
"""
240257
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+
)
241271
return plot(fig, **plot_options)
242272

243273

0 commit comments

Comments
 (0)