import plotly.plotly as py
help(py.get_figure)
Help on function get_figure in module plotly.plotly.plotly: get_figure(file_owner_or_url, file_id=None, raw=False) Returns a JSON figure representation for the specified file Plotly uniquely identifies figures with a 'file_owner'/'file_id' pair. Since each file is given a corresponding unique url, you may also simply pass a valid plotly url as the first argument. Examples: fig = get_figure('https://plot.ly/~chris/1638') fig = get_figure('chris', 1638) Note, if you're using a file_owner string as the first argument, you MUST specify a `file_id` keyword argument. Else, if you're using a url string as the first argument, you MUST NOT specify a `file_id` keyword argument, or file_id must be set to Python's None value. Positional arguments: file_owner_or_url (string) -- a valid plotly username OR a valid plotly url Keyword arguments: file_id (default=None) -- an int or string that can be converted to int if you're using a url, don't fill this in! raw (default=False) -- if true, return unicode JSON string verbatim** **by default, plotly will return a Figure object (run help(plotly .graph_objs.Figure)). This representation decodes the keys and values from unicode (if possible), removes information irrelevant to the figure representation, and converts the JSON dictionary objects to plotly `graph objects`.
etpinard573 = py.get_figure('https://plot.ly/~etpinard/573/prestige-dataset-3d-plot/')
etpinard573['data'][0]['textfont']
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-3-59b3326049ac> in <module>() 1 etpinard573 = py.get_figure('https://plot.ly/~etpinard/573/prestige-dataset-3d-plot/') ----> 2 etpinard573['data'][0]['textfont'] KeyError: 'textfont'
etpinard573_raw = py.get_figure('https://plot.ly/~etpinard/573/prestige-dataset-3d-plot/', raw=True)
etpinard573_raw['data'][0]['textfont']
{'family': u'Droid Serif, serif'}
py.iplot(etpinard573_raw)
--------------------------------------------------------------------------- PlotlyError Traceback (most recent call last) <ipython-input-5-aa57a73c1f2e> in <module>() ----> 1 py.iplot(etpinard573_raw) /usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc in iplot(figure_or_data, **plot_options) 113 if 'auto_open' not in plot_options: 114 plot_options['auto_open'] = False --> 115 res = plot(figure_or_data, **plot_options) 116 urlsplit = res.split('/') 117 username, plot_id = urlsplit[-2][1:], urlsplit[-1] # TODO: HACKY! /usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc in plot(figure_or_data, validate, **plot_options) 184 "plot option.\nHere's why you're " 185 "seeing this error:\n\n{0}" --> 186 "".format(err)) 187 if not figure['data']: 188 raise exceptions.PlotlyEmptyDataError( PlotlyError: Invalid 'figure_or_data' argument. Plotly will not be able to properly parse the resulting JSON. If you want to send this 'figure_or_data' to Plotly anyway (not recommended), you can set 'validate=False' as a plot option. Here's why you're seeing this error: Invalid key, 'textfont', for class, 'Scatter3d'. Run 'help(plotly.graph_objs.Scatter3d)' for more information. Path To Error: ['data'][0]['textfont'] Additional Notes: That key is valid only in these objects: Scatter('textfont'="dictionary-like object")
py.iplot(etpinard573_raw, validate=False)
from IPython.display import display, HTML
import urllib2
url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'
display(HTML(urllib2.urlopen(url).read()))