ts-explorations / pages /1_πŸ“ˆ_Plotting.py
laverdes's picture
fix: wide layout is set in main page
995e906
raw
history blame
2.2 kB
import streamlit as st
import pandas as pd
st.header("Plotting Time Series Data")
st.markdown("Users can load their time-series data in **.csv** format and select a particular feature and plot-type.\
Go ahead and use the sidebar on the left to upload your data files and to start visualizing it!")
def plot_collection(plot_only_this, collection, number_of_desired_plots=0):
fig = go.Figure()
plots_count = 0
print("total number of graphs: ", len(collection))
for (pattern_name, d) in collection:
if pattern_name == plot_only_this:
if plots_count ==0:
fig.add_trace(go.Line(y=d))
fig.update_layout(title=plot_only_this)
else:
fig.add_trace(go.Line(y=d))
plots_count += 1
fig.update_layout(width=1200, height=800)
if number_of_desired_plots:
if plots_count == number_of_desired_plots:
break
with st.sidebar:
plot = st.radio("Select the kind of visualization:",('Plot feature collection', 'Compare users', 'Plot distribution'))
file = st.file_uploader("Load CSV file", accept_multiple_files = False)
if file:
df = pd.read_csv(file, index_col = False)
# df.index = df['Unnamed: 0'].tolist()
del df['Unnamed: 0']
if 'df' not in st.session_state:
st.session_state['df'] = df
st.success("Your data has been successfully loaded! πŸ€—")
if 'df' in list(st.session_state.keys()):
st.markdown("Your uploaded data:")
st.dataframe(st.session_state.df)
else:
st.caption("Upload your data using the sidebar and select a plot-type to start :sunglasses:")
df_base = st.session_state.df if 'df' in list(st.session_state.keys()) else pd.DataFrame()
n = len(df_base)
col1, col2 = st.columns(2)
with col1:
if n:
st.info(f"Your data has {n} samples.")
slider_range = list(range(n))
n_plot = st.slider("How many samples do you want to plot in the same graph", slider_range[0]+1, slider_range[-1]+1, 5)
st.write(f"Action: {plot} using {n_plot} samples")
st.button("Plot now! πŸ“Š")
if not df_base.empty:
st.warning("Consider running outlier detection to clean your data!", icon="⚠️")