{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "#### New to Plotly?\n", "Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).\n", "
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).\n", "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Online Configuration Options\n", "Config options set via our API libraries are overridden on graphs hosted on plot.ly (i.e. when working online). \n", "To set configutation options online, you can edit the plot's embed url. Visit our embed tutorial: http://help.plot.ly/embed-graphs-in-websites/#step-8-customize-the-iframe for more information on customizing the embed url to remove the \"Edit Chart\" link, hide the modebar, or autosize the plot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Offline Configuration Options\n", "Now you can pass a `config` dictionary with all configurations options such as `showLink`, `linkText`, `scrollZoom`, and `displayModeBar`. For the complete list of config options check out: https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js\n", "\n", "

Remove the \"Edit Chart\" link:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode()\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config={'showLink': False}\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Edit Link Text:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode(connected=True)\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config = {'linkText': \"Let's visit plot.ly !!!\"}\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Enable Scroll Zoom" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode(connected=True)\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config = {'scrollZoom': True}\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display ModeBar" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode(connected=True)\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config = {'displayModeBar': True}\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Edit Mode - change the title and axis titles" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode(connected=True)\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config = {'editable': True}\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Multiple Config Options at Once!" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode(connected=True)\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config = {\n", " 'linkText': \"Let's visit plot.ly !!!\",\n", " 'scrollZoom': True,\n", " 'displayModeBar': True,\n", " 'editable': True\n", "}\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remove Modebar Buttons" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "data": [ { "type": "scatter", "x": [ 1, 2, 3 ], "y": [ 1, 3, 1 ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from plotly.offline import init_notebook_mode, iplot\n", "import plotly.graph_objs as go\n", "\n", "init_notebook_mode(connected=True)\n", "\n", "data = [\n", " go.Scatter(\n", " x=[1, 2, 3],\n", " y=[1, 3, 1]\n", " )\n", "]\n", "\n", "config = {\n", " 'modeBarButtonsToRemove': ['sendDataToCloud','hoverCompareCartesian']\n", "}\n", "\n", "iplot(data, config=config)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Reference" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function plot in module plotly.offline.offline:\n", "\n", "plot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True, output_type='file', include_plotlyjs=True, filename='temp-plot.html', auto_open=True, image=None, image_filename='plot_image', image_width=800, image_height=600, config=None)\n", " Create a plotly graph locally as an HTML document or string.\n", " \n", " Example:\n", " ```\n", " from plotly.offline import plot\n", " import plotly.graph_objs as go\n", " \n", " plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], filename='my-graph.html')\n", " # We can also download an image of the plot by setting the image parameter\n", " # to the image format we want\n", " plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], filename='my-graph.html',\n", " image='jpeg')\n", " ```\n", " More examples below.\n", " \n", " figure_or_data -- a plotly.graph_objs.Figure or plotly.graph_objs.Data or\n", " dict or list that describes a Plotly graph.\n", " See https://plotly.com/python/ for examples of\n", " graph descriptions.\n", " \n", " Keyword arguments:\n", " show_link (default=True) -- display a link in the bottom-right corner of\n", " of the chart that will export the chart to Chart Studio Cloud or\n", " Chart Studio Enterprise\n", " link_text (default='Export to plot.ly') -- the text of export link\n", " validate (default=True) -- validate that all of the keys in the figure\n", " are valid? omit if your version of plotly.js has become outdated\n", " with your version of graph_reference.json or if you need to include\n", " extra, unnecessary keys in your figure.\n", " output_type ('file' | 'div' - default 'file') -- if 'file', then\n", " the graph is saved as a standalone HTML file and `plot`\n", " returns None.\n", " If 'div', then `plot` returns a string that just contains the\n", " HTML
that contains the graph and the script to generate the\n", " graph.\n", " Use 'file' if you want to save and view a single graph at a time\n", " in a standalone HTML file.\n", " Use 'div' if you are embedding these graphs in an HTML file with\n", " other graphs or HTML markup, like a HTML report or an website.\n", " include_plotlyjs (default=True) -- If True, include the plotly.js\n", " source code in the output file or string.\n", " Set as False if your HTML file already contains a copy of the plotly.js\n", " library.\n", " filename (default='temp-plot.html') -- The local filename to save the\n", " outputted chart to. If the filename already exists, it will be\n", " overwritten. This argument only applies if `output_type` is 'file'.\n", " auto_open (default=True) -- If True, open the saved file in a\n", " web browser after saving.\n", " This argument only applies if `output_type` is 'file'.\n", " image (default=None |'png' |'jpeg' |'svg' |'webp') -- This parameter sets\n", " the format of the image to be downloaded, if we choose to download an\n", " image. This parameter has a default value of None indicating that no\n", " image should be downloaded. Please note: for higher resolution images\n", " and more export options, consider making requests to our image servers.\n", " Type: `help(py.image)` for more details.\n", " image_filename (default='plot_image') -- Sets the name of the file your\n", " image will be saved to. The extension should not be included.\n", " image_height (default=600) -- Specifies the height of the image in `px`.\n", " image_width (default=800) -- Specifies the width of the image in `px`.\n", " config (default=None) -- Plot view options dictionary. Keyword arguments\n", " `show_link` and `link_text` set the associated options in this\n", " dictionary if it doesn't contain them already.\n", "\n" ] } ], "source": [ "import plotly.offline as offline\n", "help(offline.plot)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/chelsea/venv/venv2/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n", "\n", "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", "\n", "/Users/chelsea/venv/venv2/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n", "\n", "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", "\n" ] } ], "source": [ "from IPython.display import display, HTML\n", "\n", "display(HTML(''))\n", "display(HTML(''))\n", "\n", "#!pip install git+https://github.com/plotly/publisher.git --upgrade\n", "import publisher\n", "publisher.publish(\n", " 'config_opts.ipynb', 'python/configuration-options/', 'Configuration',\n", " 'How to set configuration options of plotly graphs in python. Examples of both online and offline configurations.',\n", " title = 'Configuration | plotly',\n", " name = 'Configuration',\n", " language='python', has_thumbnail= True,\n", " thumbnail= 'thumbnail/modebar-icons.png',\n", " display_as='file_settings', order=7, uses_plotly_offline=True,\n", " ipynb= '~notebook_demo/97')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.14" } }, "nbformat": 4, "nbformat_minor": 1 }