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