hussain2010 commited on
Commit
58cd766
·
verified ·
1 Parent(s): c1c3428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -10
app.py CHANGED
@@ -3,6 +3,8 @@ import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import numpy as np
5
  from io import BytesIO
 
 
6
 
7
  # Function to save and download images with specified DPI
8
  def download_button(fig, file_name, file_format, dpi):
@@ -16,6 +18,22 @@ def download_button(fig, file_name, file_format, dpi):
16
  mime=f"image/{file_format.lower()}",
17
  )
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Title of the app
20
  st.set_page_config(layout="wide") # Use wide layout
21
  st.title("Advanced CSV Data Visualization App")
@@ -86,6 +104,35 @@ if uploaded_file is not None:
86
  grid_color = st.color_picker("Grid Line Color:", "#DDDDDD")
87
  grid_line_width = st.slider("Grid Line Width:", 0.5, 2.5, 1.0)
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  # Vertical Marker Settings
90
  st.subheader("Vertical Marker Settings")
91
  marker_x_values = st.text_input("Enter X-axis Values for Markers (comma-separated):", value="")
@@ -173,18 +220,21 @@ if uploaded_file is not None:
173
  # Apply scaling for X-axis
174
  df, x_unit = apply_scaling(df, x_column, scale_option, x_unit)
175
 
176
- # Apply scaling for Y-axis (same scaling options)
177
  for col in y_columns:
178
  df, y_unit = apply_scaling(df, col, y_scale_option, y_unit)
179
 
180
- # Plot data
181
  for col in y_columns:
182
- ax.plot(df[x_column], df[col],
183
- label=col,
184
- linestyle=style_settings[col]["line_style"],
185
- marker=style_settings[col]["marker_style"],
186
- color=style_settings[col]["color"],
187
- linewidth=style_settings[col]["line_width"])
 
 
 
188
 
189
  # Axis limits and step size
190
  if x_min and x_max:
@@ -225,5 +275,4 @@ if uploaded_file is not None:
225
  # Download button
226
  download_button(fig, "graph", "PNG", dpi)
227
 
228
- except Exception as e:
229
- st.error(f"Error: {str(e)}")
 
3
  import matplotlib.pyplot as plt
4
  import numpy as np
5
  from io import BytesIO
6
+ from scipy.signal import savgol_filter
7
+ from scipy.ndimage import gaussian_filter1d
8
 
9
  # Function to save and download images with specified DPI
10
  def download_button(fig, file_name, file_format, dpi):
 
18
  mime=f"image/{file_format.lower()}",
19
  )
20
 
21
+ # Function to apply smoothing
22
+ def apply_smoothing(data, method, **params):
23
+ if method == "None":
24
+ return data
25
+ elif method == "Moving Average":
26
+ window = params.get('window_size', 5)
27
+ return pd.Series(data).rolling(window=window, center=True).mean()
28
+ elif method == "Gaussian":
29
+ sigma = params.get('sigma', 2)
30
+ return gaussian_filter1d(data, sigma=sigma)
31
+ elif method == "Savitzky-Golay":
32
+ window = params.get('window_size', 5)
33
+ poly_order = params.get('poly_order', 2)
34
+ return savgol_filter(data, window_length=window, polyorder=poly_order)
35
+ return data
36
+
37
  # Title of the app
38
  st.set_page_config(layout="wide") # Use wide layout
39
  st.title("Advanced CSV Data Visualization App")
 
104
  grid_color = st.color_picker("Grid Line Color:", "#DDDDDD")
105
  grid_line_width = st.slider("Grid Line Width:", 0.5, 2.5, 1.0)
106
 
107
+ # Smoothing Settings
108
+ st.subheader("Smoothing Settings")
109
+ smoothing_method = st.selectbox(
110
+ "Smoothing Method:",
111
+ ["None", "Moving Average", "Gaussian", "Savitzky-Golay"]
112
+ )
113
+
114
+ # Smoothing parameters based on selected method
115
+ smoothing_params = {}
116
+ if smoothing_method == "Moving Average":
117
+ smoothing_params['window_size'] = st.slider(
118
+ "Window Size:",
119
+ 3, 51, 5, step=2
120
+ )
121
+ elif smoothing_method == "Gaussian":
122
+ smoothing_params['sigma'] = st.slider(
123
+ "Sigma (Blur Amount):",
124
+ 0.1, 5.0, 2.0, step=0.1
125
+ )
126
+ elif method == "Savitzky-Golay":
127
+ smoothing_params['window_size'] = st.slider(
128
+ "Window Size:",
129
+ 3, 51, 5, step=2
130
+ )
131
+ smoothing_params['poly_order'] = st.slider(
132
+ "Polynomial Order:",
133
+ 1, 5, 2
134
+ )
135
+
136
  # Vertical Marker Settings
137
  st.subheader("Vertical Marker Settings")
138
  marker_x_values = st.text_input("Enter X-axis Values for Markers (comma-separated):", value="")
 
220
  # Apply scaling for X-axis
221
  df, x_unit = apply_scaling(df, x_column, scale_option, x_unit)
222
 
223
+ # Apply scaling for Y-axis
224
  for col in y_columns:
225
  df, y_unit = apply_scaling(df, col, y_scale_option, y_unit)
226
 
227
+ # Plot data with smoothing
228
  for col in y_columns:
229
+ # Apply smoothing to the y-values
230
+ y_values = apply_smoothing(df[col].values, smoothing_method, **smoothing_params)
231
+
232
+ ax.plot(df[x_column], y_values,
233
+ label=col,
234
+ linestyle=style_settings[col]["line_style"],
235
+ marker=style_settings[col]["marker_style"],
236
+ color=style_settings[col]["color"],
237
+ linewidth=style_settings[col]["line_width"])
238
 
239
  # Axis limits and step size
240
  if x_min and x_max:
 
275
  # Download button
276
  download_button(fig, "graph", "PNG", dpi)
277
 
278
+ except Exception as e: