ZachGF commited on
Commit
1af183a
·
verified ·
1 Parent(s): 361143b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -2,27 +2,38 @@ import gradio as gr
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
 
 
 
 
5
  def plot_graph(file):
6
  df = pd.read_csv(file.name)
7
-
8
- x_axis = 'Date'
9
- y_axis = 'Count'
10
- group_label = 'Species'
11
-
12
- df[x_axis] = pd.to_datetime(df[x_axis])
13
 
14
- plt.figure()
15
- df.plot()
16
 
17
- plt.legend(title=group_label)
 
 
 
 
 
 
 
 
 
18
  plt.grid(True)
19
  plt.xticks(rotation=45)
20
 
 
21
  plot_filename = 'plot.png'
22
  plt.savefig(plot_filename)
23
  plt.close()
24
  return plot_filename
25
 
 
26
  # Define the Gradio interface
27
  interface = gr.Interface(
28
  fn=plot_graph,
 
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
 
5
+ import matplotlib.pyplot as plt
6
+ import pandas as pd
7
+
8
  def plot_graph(file):
9
  df = pd.read_csv(file.name)
10
+
11
+ # Assuming 'Date' is formatted as 'YYYY-MM-DD' in the CSV.
12
+ df['Date'] = pd.to_datetime(df['Date'])
 
 
 
13
 
14
+ # Set figure and axes
15
+ plt.figure(figsize=(10, 6))
16
 
17
+ # Plot each species as a separate line
18
+ for species in df['Species'].unique():
19
+ species_data = df[df['Species'] == species]
20
+ plt.plot(species_data['Date'], species_data['Count'], label=species, marker='o')
21
+
22
+ # Setting labels and title
23
+ plt.xlabel('Date')
24
+ plt.ylabel('Count')
25
+ plt.title('Observations of Species Over Time')
26
+ plt.legend(title='Species')
27
  plt.grid(True)
28
  plt.xticks(rotation=45)
29
 
30
+ # Save the plot
31
  plot_filename = 'plot.png'
32
  plt.savefig(plot_filename)
33
  plt.close()
34
  return plot_filename
35
 
36
+
37
  # Define the Gradio interface
38
  interface = gr.Interface(
39
  fn=plot_graph,