- Contents
- st.area_chart
- element.add_rows
st.area_chart
Display an area 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 Altair spec. As a result this is easier to use for many "just plot this" scenarios, while being less customizable.
If st.area_chart does not guess the data specification correctly, try specifying your desired chart using st.altair_chart.
| Function signature[source] | |
|---|---|
st.area_chart(data=None, *, x=None, y=None, color=None, width=None, height=None, use_container_width=True) | |
| Parameters | |
data (pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, or dict) | 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 to use for different series in this chart. For an area chart with just 1 series, this can be:
For an area chart with multiple series, where the dataframe is in long format (that is, y is None or just one column), this can be:
For an area chart with multiple series, where the dataframe is in wide format (that is, y is a Sequence of columns), this can be:
|
width (int or None) | Desired width of the chart expressed in pixels. If width is None (default), Streamlit sets the width of the chart to fit its contents according to the plotting library, up to the width of the parent container. If width is greater than the width of the parent container, Streamlit sets the chart width to match the width of the parent container. |
height (int or None) | Desired height of the chart expressed in pixels. If height is None (default), Streamlit sets the height of the chart to fit its contents according to the plotting library. |
use_container_width (bool) | Whether to override width with the width of the parent container. If use_container_width is False (default), Streamlit sets the chart's width according to width. If use_container_width is True, Streamlit sets the width of the chart to match the width of the parent container. |
Examples
PythonYou 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):
PythonFinally, if your dataframe is in wide format, you can group multiple columns under the y argument to show multiple series with different colors:
Python
element.add_rows
Deprecation notice
We plan to deprecate .add_rows(). Please leave feedback.
Concatenate a dataframe to the bottom of the current one.
| Function signature[source] | |
|---|---|
element.add_rows(data=None, **kwargs) | |
| Parameters | |
data (pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, Iterable, dict, or None) | Table to concat. Optional. |
**kwargs (pandas.DataFrame, numpy.ndarray, Iterable, dict, or None) | The named dataset to concat. Optional. You can only pass in 1 dataset (including the one in the data parameter). |
Example
PythonYou can do the same thing with plots. For example, if you want to add more data to a line chart:
PythonAnd for plots whose datasets are named, you can pass the data with a keyword argument where the key is the name:
Python
Still have questions?
Our forums are full of helpful information and Streamlit experts.
