{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Get figure with raw option\n",
"\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import plotly.plotly as py"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on function get_figure in module plotly.plotly.plotly:\n",
"\n",
"get_figure(file_owner_or_url, file_id=None, raw=False)\n",
" Returns a JSON figure representation for the specified file\n",
" \n",
" Plotly uniquely identifies figures with a 'file_owner'/'file_id' pair.\n",
" Since each file is given a corresponding unique url, you may also simply\n",
" pass a valid plotly url as the first argument.\n",
" \n",
" Examples:\n",
" fig = get_figure('https://plot.ly/~chris/1638')\n",
" fig = get_figure('chris', 1638)\n",
" \n",
" Note, if you're using a file_owner string as the first argument, you MUST\n",
" specify a `file_id` keyword argument. Else, if you're using a url string\n",
" as the first argument, you MUST NOT specify a `file_id` keyword argument, or\n",
" file_id must be set to Python's None value.\n",
" \n",
" Positional arguments:\n",
" file_owner_or_url (string) -- a valid plotly username OR a valid plotly url\n",
" \n",
" Keyword arguments:\n",
" file_id (default=None) -- an int or string that can be converted to int\n",
" if you're using a url, don't fill this in!\n",
" raw (default=False) -- if true, return unicode JSON string verbatim**\n",
" \n",
" **by default, plotly will return a Figure object (run help(plotly\n",
" .graph_objs.Figure)). This representation decodes the keys and values from\n",
" unicode (if possible), removes information irrelevant to the figure\n",
" representation, and converts the JSON dictionary objects to plotly\n",
" `graph objects`.\n",
"\n"
]
}
],
"source": [
"help(py.get_figure)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "KeyError",
"evalue": "'textfont'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0metpinard573\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_figure\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'https://plot.ly/~etpinard/573/prestige-dataset-3d-plot/'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0metpinard573\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'data'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'textfont'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m: 'textfont'"
]
}
],
"source": [
"etpinard573 = py.get_figure('https://plot.ly/~etpinard/573/prestige-dataset-3d-plot/')\n",
"etpinard573['data'][0]['textfont']"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'family': u'Droid Serif, serif'}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"etpinard573_raw = py.get_figure('https://plot.ly/~etpinard/573/prestige-dataset-3d-plot/', raw=True)\n",
"etpinard573_raw['data'][0]['textfont']"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "PlotlyError",
"evalue": "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.\nHere's why you're seeing this error:\n\nInvalid key, 'textfont', for class, 'Scatter3d'.\n\nRun 'help(plotly.graph_objs.Scatter3d)' for more information.\n\nPath To Error:\n['data'][0]['textfont']\n\nAdditional Notes:\nThat key is valid only in these objects:\n\n\tScatter('textfont'=\"dictionary-like object\")\n",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mPlotlyError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0metpinard573_raw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m/usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc\u001b[0m in \u001b[0;36miplot\u001b[1;34m(figure_or_data, **plot_options)\u001b[0m\n\u001b[0;32m 113\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;34m'auto_open'\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mplot_options\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 114\u001b[0m \u001b[0mplot_options\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'auto_open'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 115\u001b[1;33m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfigure_or_data\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mplot_options\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 116\u001b[0m \u001b[0murlsplit\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mres\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'/'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 117\u001b[0m \u001b[0musername\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mplot_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0murlsplit\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murlsplit\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;31m# TODO: HACKY!\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m/usr/local/lib/python2.7/dist-packages/plotly/plotly/plotly.pyc\u001b[0m in \u001b[0;36mplot\u001b[1;34m(figure_or_data, validate, **plot_options)\u001b[0m\n\u001b[0;32m 184\u001b[0m \u001b[1;34m\"plot option.\\nHere's why you're \"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 185\u001b[0m \u001b[1;34m\"seeing this error:\\n\\n{0}\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 186\u001b[1;33m \"\".format(err))\n\u001b[0m\u001b[0;32m 187\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mfigure\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'data'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 188\u001b[0m raise exceptions.PlotlyEmptyDataError(\n",
"\u001b[1;31mPlotlyError\u001b[0m: 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.\nHere's why you're seeing this error:\n\nInvalid key, 'textfont', for class, 'Scatter3d'.\n\nRun 'help(plotly.graph_objs.Scatter3d)' for more information.\n\nPath To Error:\n['data'][0]['textfont']\n\nAdditional Notes:\nThat key is valid only in these objects:\n\n\tScatter('textfont'=\"dictionary-like object\")\n"
]
}
],
"source": [
"py.iplot(etpinard573_raw)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"py.iplot(etpinard573_raw, validate=False)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import display, HTML\n",
"import urllib2\n",
"url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'\n",
"display(HTML(urllib2.urlopen(url).read()))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}