Team Ai
Apppublic

biodivx/matplotlib-demo

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py50 linesDownload Raw Back to root
1import gradio as gr2import pandas as pd3import matplotlib.pyplot as plt4 5import matplotlib.pyplot as plt6import pandas as pd7 8def 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 axes15    plt.figure(figsize=(10, 6))16    17    # Plot each species as a separate line18    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 title23    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 plot31    plot_filename = 'plot.png'32    plt.savefig(plot_filename)33    plt.close()34    return plot_filename35 36 37examples = [38    ["example1.csv"],39]40 41interface = gr.Interface(42    fn=plot_graph,43    inputs=gr.File(label="Upload CSV File"),44    outputs=gr.Image(type="filepath", label="Generated Graph"),45    title="Species Observation Plotter",46    examples=examples47)48 49interface.launch()50