hi @hahahazel
st.line_chart is a wrapper around the Altair library. st.line_char can only be used in very simple cases, outside of *hello world applications", you quickly need to use a graphic library. See below how to create the graphic with Altair. Note, that I have added a date column to your dataframe to be used as an x-axis. Also, Altair works best if your dataframe is melted, which means, that instead of having a column for each parameter, one value is stored per row in 2 columns: one column holding the parameter name, another column to hold the value. It’s a bit more code, but Iif you want to use plots in a productive setting, you need to use a graphics library: Altair is a good choice, but plotly, matplotlib or bokeh are other great candidates that are easy to use in Streamlit. Hope that helps.
import streamlit as st
import pandas as pd
import altair as alt
import numpy as np
df = pd.DataFrame(
np.random.rand(10, 4),
columns= ["NO2","C2H5CH","VOC","CO"])
# generate a date range to be used as the x axis
df['date'] = pd.date_range("2014-01-01", periods=10, freq="m")
df_melted = pd.melt(df,id_vars=['date'],var_name='parameter', value_name='value')
c = alt.Chart(df_melted, title='measure of different elements over time').mark_line().encode(
x='date', y='value', color='parameter')
st.altair_chart(c, use_container_width=True)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.