Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +66 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,68 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import plotly.graph_objects as go
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
|
| 6 |
+
#Read Avocado Dataset
|
| 7 |
+
data = pd.read_csv("./files/avocado.csv")
|
| 8 |
+
|
| 9 |
+
st.header("Pie Chart")
|
| 10 |
+
# Implementing Pie Plot
|
| 11 |
+
pie_chart = go.Figure(
|
| 12 |
+
go.Pie(labels = data.type,
|
| 13 |
+
values = data.AveragePrice,
|
| 14 |
+
hoverinfo = "label+percent",
|
| 15 |
+
textinfo = "value+percent"
|
| 16 |
+
))
|
| 17 |
+
|
| 18 |
+
st.plotly_chart(pie_chart)
|
| 19 |
+
|
| 20 |
+
st.header("Donut Chart")
|
| 21 |
+
# Donut Chart
|
| 22 |
+
donut_chart = px.pie(
|
| 23 |
+
names = data.type,
|
| 24 |
+
values = data.AveragePrice,
|
| 25 |
+
hole=0.25,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
st.plotly_chart(donut_chart)
|
| 29 |
+
|
| 30 |
+
st.header("Scatter Chart")
|
| 31 |
+
#Scatter
|
| 32 |
+
scat = px.scatter(
|
| 33 |
+
x = data.Date,
|
| 34 |
+
y = data.AveragePrice
|
| 35 |
+
)
|
| 36 |
+
st.plotly_chart(scat)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Minimizing Dataset
|
| 40 |
+
albany_df = data[data['region']=="Albany"]
|
| 41 |
+
al_df = albany_df[albany_df["year"]==2015]
|
| 42 |
+
#Line
|
| 43 |
+
line_chart = px.line(
|
| 44 |
+
x = al_df["Date"],
|
| 45 |
+
y = al_df["Large Bags"]
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
line_chart.update_traces(line_color = "orange")
|
| 49 |
+
st.header("Line Chart")
|
| 50 |
+
st.plotly_chart(line_chart)
|
| 51 |
+
|
| 52 |
+
# Bar graph
|
| 53 |
+
bar_graph = px.bar(
|
| 54 |
+
al_df,
|
| 55 |
+
title = "Bar Graph",
|
| 56 |
+
x = "Date",
|
| 57 |
+
y = "Large Bags"
|
| 58 |
+
)
|
| 59 |
+
st.plotly_chart(bar_graph)
|
| 60 |
|
| 61 |
+
#Bar Color
|
| 62 |
+
bar_graph = px.bar(
|
| 63 |
+
x = al_df["Date"],
|
| 64 |
+
y = al_df["Large Bags"],
|
| 65 |
+
title = "Bar Graph",
|
| 66 |
+
color=al_df["Large Bags"]
|
| 67 |
+
)
|
| 68 |
+
st.plotly_chart(bar_graph)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|