Show Sidebar Hide Sidebar

Updating Plotly Graphs in Python

How to update your graphs in Python with the fileopt parameter.

Overwriting existing graphs and updating a graph at its unique URL

By default, Plotly will overwrite files made with the same filename:

import plotly.plotly as py
from plotly.graph_objs import *

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

plot_url = py.plot(data, filename='my plot')

If a graph named 'my plot' already exists in your account, then it will be overwritten with this new version and the URL of the graph will persist.

Saving to a folder

Filenames that contain "/" be treated as a Plotly directory and will be saved to your Plotly account in a folder tree. For example, to save your graphs to the folder my-graphs:

py.plot(data, filename='my-graphs/my plot')

If the folder doesn't exist, it will be created.

Creating new files

import plotly.plotly as py
from plotly.graph_objs import *

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

plot_url = py.plot(data, filename='new plot', fileopt='new')

With fileopt='new', Plotly will always create a new file. If a file with the same name already exists, then Plotly will append a '(1)' to the end of the filename, e.g. new plot (1) and create a unique URL.

Extending traces in an existing graph

fileopt='extend' will extend existing traces with your new data. If you need need to update your graphs in real-time (more frequently than once a minute), then use the streaming API.
Example
import plotly.plotly as py
from plotly.graph_objs import *

trace0 = Scatter(
    x=[1, 2],
    y=[1, 2]
)

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

trace2 = Scatter(
    x=[1, 2],
    y=[3, 4]
)

data = Data([trace0, trace1, trace2])

# Take 1: if there is no data in the plot, 'extend' will create new traces.
plot_url = py.plot(data, filename='extend plot', fileopt='extend')

Then, extend the traces with more data.

import plotly.plotly as py
from plotly.graph_objs import *

trace0 = Scatter(
    x=[3, 4],
    y=[2, 1]
)

trace1 = Scatter(
    x=[3, 4],
    y=[3, 2]
)

trace2 = Scatter(
    x=[3, 4],
    y=[4, 3]
)

data = Data([trace0, trace1, trace2])

# Take 2: extend the traces on the plot with the data in the order supplied.
plot_url = py.plot(data, filename='extend plot', fileopt='extend')
Still need help?
Contact Us

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