Show Sidebar Hide Sidebar

Configuration in Python

How to set configuration options of plotly graphs in python. Examples of both online and offline configurations.

New to Plotly?¶

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!

Online Configuration Options¶

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.

Offline Configuration Options¶

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:

In [1]:
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *

init_notebook_mode(connected=True)

data = Data([
    Scatter(
        x=[1, 2, 3],
        y=[1, 3, 1]
    )
])

config={'showLink': False}
iplot(data, config=config)

Edit Link Text:

In [2]:
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *

init_notebook_mode(connected=True)

data = Data([
    Scatter(
        x=[1, 2, 3],
        y=[1, 3, 1]
    )
])

config = {'linkText': "Let's visit plot.ly !!!"}
iplot(data, config=config)

Enable Scroll Zoom

In [3]:
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *

init_notebook_mode(connected=True)

data = Data([
    Scatter(
        x=[1, 2, 3],
        y=[1, 3, 1]
    )
])

config = {'scrollZoom': True}
iplot(data, config=config)

Display ModeBar

In [4]:
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *

init_notebook_mode(connected=True)

data = Data([
    Scatter(
        x=[1, 2, 3],
        y=[1, 3, 1]
    )
])

config = {'displayModeBar': True}
iplot(data, config=config)

Edit Mode - change the title and axis titles

In [5]:
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *

init_notebook_mode(connected=True)

data = Data([
    Scatter(
        x=[1, 2, 3],
        y=[1, 3, 1]
    )
])

config = {'editable': True}
iplot(data, config=config)

Multiple Config Options at Once!

In [6]:
from plotly.offline import init_notebook_mode, iplot
from plotly.graph_objs import *

init_notebook_mode(connected=True)

data = Data([
    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)

Reference¶

In [7]:
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://plot.ly/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 Plotly Cloud or
        Plotly 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.

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.