matplotlib-demo / app.py
ZachGF's picture
Update app.py
1af183a verified
raw
history blame
1.16 kB
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import pandas as pd
def plot_graph(file):
df = pd.read_csv(file.name)
# Assuming 'Date' is formatted as 'YYYY-MM-DD' in the CSV.
df['Date'] = pd.to_datetime(df['Date'])
# Set figure and axes
plt.figure(figsize=(10, 6))
# Plot each species as a separate line
for species in df['Species'].unique():
species_data = df[df['Species'] == species]
plt.plot(species_data['Date'], species_data['Count'], label=species, marker='o')
# Setting labels and title
plt.xlabel('Date')
plt.ylabel('Count')
plt.title('Observations of Species Over Time')
plt.legend(title='Species')
plt.grid(True)
plt.xticks(rotation=45)
# Save the plot
plot_filename = 'plot.png'
plt.savefig(plot_filename)
plt.close()
return plot_filename
# Define the Gradio interface
interface = gr.Interface(
fn=plot_graph,
inputs=gr.File(label="Upload CSV File"),
outputs=gr.Image(type="filepath", label="Generated Graph"),
title="Tabular Data Plotter"
)
interface.launch()