Sending Data to Charts in Python/v3

How to send data to charts in Python. Examples of overwriting charts with new data, extending traces, and adding new traces.


Note: this page is part of the documentation for version 3 of Plotly.py, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.
# Learn about API authentication here: https://plotly.com/python/getting-started
# Find your api_key here: https://plotly.com/settings/api

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')
The simplest and recommended way to update a chart remotely.
You can overwrite a chart's data with new data remotely, simply by including its file name in the filename kwarg.
Note that setting a filename overwrites the entire chart (i.e., style & layout settings are not preserved).
# Learn about API authentication here: https://plotly.com/python/getting-started
# Find your api_key here: https://plotly.com/settings/api

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

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

data = Data( [ new_data ] )

plot_url = py.plot(data, filename='extend plot', fileopt='extend')
Add data to an existing trace by setting fileopt='extend'.
This method is used for embedded systems that may not have the memory for a full overwrite of the chart data in one API call.
# Learn about API authentication here: https://plotly.com/python/getting-started
# Find your api_key here: https://plotly.com/settings/api

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

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

data = Data( [ new_trace1 ] )

plot_url = py.plot(data, filename='append plot', fileopt='append')
NOT RECOMMENDED
When updating a chart's data remotely, we recommend overwriting all of the chart's data instead of adding new traces.