Display a scatterplot chart.
This is syntax-sugar around st.altair_chart. The main difference is this command uses the data's own column and indices to figure out the chart's spec. As a result this is easier to use for many "just plot this" scenarios, while being less customizable.
If st.scatter_chart does not guess the data specification correctly, try specifying your desired chart using st.altair_chart.
st.scatter_chart(data=None, *, x=None, y=None, color=None, size=None, width=0, height=0, use_container_width=True)
data (pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, dict or None)
Data to be plotted.
x (str or None)
Column name to use for the x-axis. If None, uses the data index for the x-axis.
y (str, Sequence of str, or None)
Column name(s) to use for the y-axis. If a Sequence of strings, draws several series on the same chart by melting your wide-format table into a long-format table behind the scenes. If None, draws the data of all remaining columns as data series.
color (str, tuple, Sequence of str, Sequence of tuple, or None)
The color of the circles representing each datapoint.
This can be:
If the dataframe is in wide format (that is, y is a Sequence of columns), this can also be:
size (str, float, int, or None)
The size of the circles representing each point.
This can be:
The chart width in pixels. If 0, selects the width automatically.
The chart height in pixels. If 0, selects the height automatically.
If True, set the chart width to the column width. This takes precedence over the width argument.
import streamlit as st import pandas as pd import numpy as np chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"]) st.scatter_chart(chart_data)
You can also choose different columns to use for x and y, as well as set the color dynamically based on a 3rd column (assuming your dataframe is in long format):import streamlit as st import pandas as pd import numpy as np chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"]) chart_data['col4'] = np.random.choice(['A','B','C'], 20) st.scatter_chart( chart_data, x='col1', y='col2', color='col4', size='col3', )
Finally, if your dataframe is in wide format, you can group multiple columns under the y argument to show multiple series with different colors:import streamlit as st import pandas as pd import numpy as np chart_data = pd.DataFrame(np.random.randn(20, 4), columns=["col1", "col2", "col3", "col4"]) st.scatter_chart( chart_data, x='col1', y=['col2', 'col3'], size='col4', color=['#FF0000', '#0000FF'], # Optional )
Still have questions?
Our forums are full of helpful information and Streamlit experts.