Now I made a dashboard where you can select which measurement among temp, voc, humidity and others to chart and the tower_id too. Now I plan to make a multi-line plot where each line will be a date selected in the date multibox selection. The x axis will always be the time while the y-axis will be the measurement selected.
Now Here is the problem......the x axis keeps extending as I add a date. I don't want the x-axis to extend. I want my chart to be like this (see image below)
I want a multi-line pot like the one above not like the previous image.
import pandas as pd
import streamlit as st
import plotly.express as px
@st.cache_data
def load_data():
data = pd.read_csv('2023.csv', usecols=['tower_id', 'pm2_5', 'humidity', 'temp', 'voc', 'pressure', 'date', 'time'])
return data
data = load_data()
tower_ids = data['tower_id'].unique()
selected_measurement = st.selectbox('Select Measurement', ('pm2_5', 'humidity', 'temp', 'voc', 'pressure'))
selected_tower = st.selectbox('Which Tower would you want to select?', tower_ids)
dates = data['date'].unique()
filtered_data = data[(data['tower_id'] == selected_tower)]
selected_dates = st.multiselect('Select date(s)', dates)
data['time'] = data['time'].astype(str)
filtered_data = filtered_data[filtered_data['date'].isin(selected_dates)]
fig = px.line(filtered_data, x='time', y=selected_measurement, title="Title", color='date')
st.plotly_chart(fig, use_container_width=True)
I tried to make the date into a string but that did not work.