Display an interactive Plotly chart.
Plotly is a charting library for Python. The arguments to this function closely follow the ones for Plotly's plot() function. You can find more about Plotly at https://plot.ly/python.
To show Plotly charts in Streamlit, call st.plotly_chart wherever you would call Plotly's py.plot or py.iplot.
Function signature | |
---|---|
st.plotly_chart(figure_or_data, use_container_width=False, sharing="streamlit", **kwargs) | |
Parameters | |
figure_or_data (plotly.graph_objs.Figure, plotly.graph_objs.Data,) | dict/list of plotly.graph_objs.Figure/Data See https://plot.ly/python/ for examples of graph descriptions. |
use_container_width (bool) | If True, set the chart width to the column width. This takes precedence over the figure's native width value. |
sharing ({'streamlit', 'private', 'secret', 'public'}) | Use 'streamlit' to insert the plot and all its dependencies directly in the Streamlit app using plotly's offline mode (default). Use any other sharing mode to send the chart to Plotly chart studio, which requires an account. See https://plotly.com/chart-studio/ for more information. |
**kwargs (null) | Any argument accepted by Plotly's plot() function. |
Example
The example below comes straight from the examples at https://plot.ly/python:
import streamlit as st import plotly.figure_factory as ff import numpy as np # Add histogram data x1 = np.random.randn(200) - 2 x2 = np.random.randn(200) x3 = np.random.randn(200) + 2 # Group data together hist_data = [x1, x2, x3] group_labels = ['Group 1', 'Group 2', 'Group 3'] # Create distplot with custom bin_size fig = ff.create_distplot( hist_data, group_labels, bin_size=[.1, .25, .5]) # Plot! st.plotly_chart(fig, use_container_width=True)(view standalone Streamlit app)