VarunRavichander commited on
Commit
ec94869
·
verified ·
1 Parent(s): a34273f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -48,7 +48,7 @@ if uploaded_file:
48
 
49
  # Column selection
50
  st.subheader("Select Data for Plotting")
51
- x_column = st.selectbox("Select X-axis column (Date/Time)", df.columns)
52
  y_columns = st.multiselect("Select Y-axis column(s)", [col for col in df.columns if col != x_column])
53
 
54
  if y_columns:
@@ -81,11 +81,8 @@ if uploaded_file:
81
  # Generate plot
82
  if st.button("Generate Graph"):
83
  # Convert date column to datetime if it's not already
84
- if not pd.api.types.is_datetime64_any_dtype(df[x_column]):
85
- df[x_column] = pd.to_datetime(df[x_column])
86
-
87
- # Sort the dataframe by date to ensure proper time sequence
88
- df = df.sort_values(by=x_column)
89
 
90
  # Create figure with vibrant colors
91
  fig = px.line(df, x=x_column, y=y_columns,
@@ -129,12 +126,11 @@ if uploaded_file:
129
  linewidth=1,
130
  linecolor='black',
131
  mirror=True,
132
- tickangle=-90, # Angled text for better readability
133
  title_text=x_axis_label,
134
  title_font=dict(family="Times New Roman", color="black"),
135
  tickfont=dict(family="Times New Roman", color="black", size=10),
136
- type='date', # Changed from 'category' to 'date'
137
- tickformat="%d-%m-%Y" # Format for displaying dates
138
  ),
139
  yaxis=dict(
140
  showgrid=True,
 
48
 
49
  # Column selection
50
  st.subheader("Select Data for Plotting")
51
+ x_column = st.selectbox("Select X-axis column (Date)", df.columns)
52
  y_columns = st.multiselect("Select Y-axis column(s)", [col for col in df.columns if col != x_column])
53
 
54
  if y_columns:
 
81
  # Generate plot
82
  if st.button("Generate Graph"):
83
  # Convert date column to datetime if it's not already
84
+ if pd.api.types.is_datetime64_any_dtype(df[x_column]) or pd.api.types.is_string_dtype(df[x_column]):
85
+ df[x_column] = pd.to_datetime(df[x_column]).dt.strftime('%d-%m-%Y') # Format dates as dd-mm-yyyy
 
 
 
86
 
87
  # Create figure with vibrant colors
88
  fig = px.line(df, x=x_column, y=y_columns,
 
126
  linewidth=1,
127
  linecolor='black',
128
  mirror=True,
129
+ tickangle=-90, # Vertical text
130
  title_text=x_axis_label,
131
  title_font=dict(family="Times New Roman", color="black"),
132
  tickfont=dict(family="Times New Roman", color="black", size=10),
133
+ type='category' # This ensures dates are treated as categories
 
134
  ),
135
  yaxis=dict(
136
  showgrid=True,