Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import plotly.graph_objects as go | |
| import pandas as pd | |
| import plotly.express as px | |
| from plotly.subplots import make_subplots | |
| #Read Avocado Dataset | |
| data = pd.read_csv("src/avocado.csv") | |
| st.header("Pie Chart") | |
| # Implementing Pie Plot | |
| pie_chart = go.Figure( | |
| go.Pie(labels = data.type, | |
| values = data.AveragePrice, | |
| hoverinfo = "label+percent", | |
| textinfo = "value+percent" | |
| )) | |
| st.plotly_chart(pie_chart) | |
| st.header("Donut Chart") | |
| # Donut Chart | |
| donut_chart = px.pie( | |
| names = data.type, | |
| values = data.AveragePrice, | |
| hole=0.25, | |
| ) | |
| st.plotly_chart(donut_chart) | |
| st.header("Scatter Chart") | |
| #Scatter | |
| scat = px.scatter( | |
| x = data.Date, | |
| y = data.AveragePrice | |
| ) | |
| st.plotly_chart(scat) | |
| # Minimizing Dataset | |
| albany_df = data[data['region']=="Albany"] | |
| al_df = albany_df[albany_df["year"]==2015] | |
| #Line | |
| line_chart = px.line( | |
| x = al_df["Date"], | |
| y = al_df["Large Bags"] | |
| ) | |
| line_chart.update_traces(line_color = "orange") | |
| st.header("Line Chart") | |
| st.plotly_chart(line_chart) | |
| # Bar graph | |
| st.header("Bar Graph") | |
| bar_graph = px.bar( | |
| al_df, | |
| title = "Bar Graph", | |
| x = "Date", | |
| y = "Large Bags" | |
| ) | |
| st.plotly_chart(bar_graph) | |
| #Bar Color | |
| st.header("Bar Graph with Color") | |
| bar_graph = px.bar( | |
| x = al_df["Date"], | |
| y = al_df["Large Bags"], | |
| title = "Bar Graph", | |
| color=al_df["Large Bags"] | |
| ) | |
| st.plotly_chart(bar_graph) | |
| # Horizontal Bar Graph | |
| st.header("Horizontal Bar Graph") | |
| bar_graph = px.bar( | |
| al_df, | |
| x = "Large Bags", | |
| y = "Date", | |
| title = "Bar Graph", | |
| color="Large Bags", | |
| orientation='h' | |
| ) | |
| st.plotly_chart(bar_graph) | |
| st.header("Subplots") | |
| fig = make_subplots(rows=3, cols=1) | |
| # First Subplot | |
| fig.add_trace(go.Scatter( | |
| x=al_df["Date"], | |
| y=al_df["Total Bags"], | |
| ), row=1, col=1) | |
| # Second SubPlot | |
| fig.add_trace(go.Scatter( | |
| x=al_df["Date"], | |
| y=al_df["Small Bags"], | |
| ), row=2, col=1) | |
| # Third SubPlot | |
| fig.add_trace(go.Scatter( | |
| x=al_df["Date"], | |
| y=al_df["Large Bags"], | |
| ), row=3, col=1) | |
| st.plotly_chart(fig) |