@@ -56,7 +56,8 @@ def init_notebook_mode():
56
56
'</script>' ))
57
57
58
58
59
- def iplot (figure_or_data , show_link = True , link_text = 'Export to plot.ly' ):
59
+ def iplot (figure_or_data , show_link = True , link_text = 'Export to plot.ly' ,
60
+ validate = True ):
60
61
"""
61
62
Draw plotly graphs inside an IPython notebook without
62
63
connecting to an external server.
@@ -74,6 +75,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly'):
74
75
of the chart that will export the chart to
75
76
Plotly Cloud or Plotly Enterprise
76
77
link_text (default='Export to plot.ly') -- the text of export link
78
+ validate (default=True) -- validate that all of the keys in the figure
79
+ are valid? omit if your version of plotly.js
80
+ has become outdated with your version of
81
+ graph_reference.json or if you need to include
82
+ extra, unnecessary keys in your figure.
77
83
78
84
Example:
79
85
```
@@ -96,15 +102,10 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly'):
96
102
raise ImportError ('`iplot` can only run inside an IPython Notebook.' )
97
103
98
104
from IPython .display import HTML , display
99
- if isinstance (figure_or_data , dict ):
100
- data = figure_or_data ['data' ]
101
- layout = figure_or_data .get ('layout' , {})
102
- else :
103
- data = figure_or_data
104
- layout = {}
105
+ figure = tools .return_figure_from_figure_or_data (figure_or_data , validate )
105
106
106
- width = layout .get ('width' , '100%' )
107
- height = layout .get ('height' , 525 )
107
+ width = figure . get ( ' layout' , {}) .get ('width' , '100%' )
108
+ height = figure . get ( ' layout' , {}) .get ('height' , 525 )
108
109
try :
109
110
float (width )
110
111
except (ValueError , TypeError ):
@@ -120,8 +121,8 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly'):
120
121
width = str (width ) + 'px'
121
122
122
123
plotdivid = uuid .uuid4 ()
123
- jdata = json .dumps (data , cls = utils .PlotlyJSONEncoder )
124
- jlayout = json .dumps (layout , cls = utils .PlotlyJSONEncoder )
124
+ jdata = json .dumps (figure . get ( ' data' , []) , cls = utils .PlotlyJSONEncoder )
125
+ jlayout = json .dumps (figure . get ( ' layout' , {}) , cls = utils .PlotlyJSONEncoder )
125
126
126
127
if show_link is False :
127
128
link_text = ''
0 commit comments