Spaces:
No application file
No application file
Upload 4 files
Browse files- README (1).md +12 -0
- app (1).py +230 -0
- bloom_dataset.pkl +3 -0
- requirements (1).txt +3 -0
README (1).md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: 🧠Visualization Plotly Sunbursts Treemaps WebGL🩺
|
3 |
+
emoji: 6-Vis🧠
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: purple
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.17.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app (1).py
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import plotly.express as px
|
4 |
+
import pandas as pd
|
5 |
+
import plotly.graph_objects as go
|
6 |
+
|
7 |
+
st.set_page_config(page_title="Plotly Graphing Libraries",layout='wide')
|
8 |
+
|
9 |
+
import streamlit as st
|
10 |
+
|
11 |
+
uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=True)
|
12 |
+
for uploaded_file in uploaded_files:
|
13 |
+
bytes_data = uploaded_file.read()
|
14 |
+
st.write("filename:", uploaded_file.name)
|
15 |
+
st.write(bytes_data)
|
16 |
+
|
17 |
+
if st.checkbox("FileDetails"):
|
18 |
+
|
19 |
+
filevalue = uploaded_file.getvalue()
|
20 |
+
st.write(filevalue)
|
21 |
+
st.write(uploaded_file.name)
|
22 |
+
st.write(uploaded_file.type)
|
23 |
+
st.write(uploaded_file.size)
|
24 |
+
#st.write(uploaded_file.last_modified)
|
25 |
+
#st.write(uploaded_file.charset)
|
26 |
+
st.write(uploaded_file.getbuffer())
|
27 |
+
st.write(uploaded_file.getbuffer().nbytes)
|
28 |
+
st.write(uploaded_file.getbuffer().tobytes())
|
29 |
+
st.write(uploaded_file.getbuffer().tolist())
|
30 |
+
st.write(uploaded_file.getbuffer().itemsize)
|
31 |
+
st.write(uploaded_file.getbuffer().ndim)
|
32 |
+
st.write(uploaded_file.getbuffer().shape)
|
33 |
+
st.write(uploaded_file.getbuffer().strides)
|
34 |
+
st.write(uploaded_file.getbuffer().suboffsets)
|
35 |
+
st.write(uploaded_file.getbuffer().readonly)
|
36 |
+
st.write(uploaded_file.getbuffer().c_contiguous)
|
37 |
+
st.write(uploaded_file.getbuffer().f_contiguous)
|
38 |
+
st.write(uploaded_file.getbuffer().contiguous)
|
39 |
+
st.write(uploaded_file.getbuffer().itemsize)
|
40 |
+
st.write(uploaded_file.getbuffer().nbytes)
|
41 |
+
st.write(uploaded_file.getbuffer().ndim)
|
42 |
+
st.write(uploaded_file.getbuffer().shape)
|
43 |
+
st.write(uploaded_file.getbuffer().strides)
|
44 |
+
st.write(uploaded_file.getbuffer().suboffsets)
|
45 |
+
st.write(uploaded_file.getbuffer().readonly)
|
46 |
+
st.write(uploaded_file.getbuffer().c_contiguous)
|
47 |
+
st.write(uploaded_file.getbuffer().f_contiguous)
|
48 |
+
st.write(uploaded_file.getbuffer().contiguous)
|
49 |
+
st.write(uploaded_file.getbuffer().itemsize)
|
50 |
+
st.write(uploaded_file.getbuffer().nbytes)
|
51 |
+
st.write(uploaded_file.getbuffer().ndim)
|
52 |
+
st.write(uploaded_file.getbuffer().shape)
|
53 |
+
st.write(uploaded_file.getbuffer().strides)
|
54 |
+
st.write(uploaded_file.getbuffer().suboffsets)
|
55 |
+
st.write(uploaded_file.getbuffer().readonly)
|
56 |
+
st.write(uploaded_file.getbuffer().c_contiguous)
|
57 |
+
st.write(uploaded_file.getbuffer().f_contiguous)
|
58 |
+
myDF = pd.DataFrame(uploaded_file.getbuffer().tolist())
|
59 |
+
|
60 |
+
|
61 |
+
st.markdown("# Treemaps from upload data file: https://plotly.com/python/treemaps/")
|
62 |
+
#df = myDF.query("year == 2007")
|
63 |
+
df = myDF
|
64 |
+
fig = px.treemap(df, path=[px.Constant("time"), 'message', 'name'], values='content',
|
65 |
+
color='lifeExp', hover_data=['iso_alpha'],
|
66 |
+
color_continuous_scale='RdBu',
|
67 |
+
color_continuous_midpoint=np.average(df['name'], weights=df['content'])) # todo - debug this and get it working with the data
|
68 |
+
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
|
69 |
+
#fig.show()
|
70 |
+
st.plotly_chart(fig, use_container_width=True)
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
#show replace
|
76 |
+
if st.checkbox("replace"):
|
77 |
+
mydf = st.dataframe(df)
|
78 |
+
columns = st.selectbox("Select column", df.columns)
|
79 |
+
old_values = st.multiselect("Current Values",list(df[columns].unique()),list(df[columns].unique()))
|
80 |
+
with st.form(key='my_form'):
|
81 |
+
col1,col2 = st.beta_columns(2)
|
82 |
+
st_input = st.number_input if is_numeric_dtype(df[columns]) else st.text_input
|
83 |
+
with col1:
|
84 |
+
old_val = st_input("old value")
|
85 |
+
with col2:
|
86 |
+
new_val = st_input("new value")
|
87 |
+
if st.form_submit_button("Replace"):
|
88 |
+
df[columns]=df[columns].replace(old_val,new_val)
|
89 |
+
st.success("{} replace with {} successfully ".format(old_val,new_val))
|
90 |
+
excel = df.to_excel(r"F:\book2.xlsx", index = False, header=True,encoding="utf-8")
|
91 |
+
df =pd.read_excel(r"F:\book2.xlsx")
|
92 |
+
mydf.add_rows(df)
|
93 |
+
|
94 |
+
st.markdown("WebGL Rendering with 1,000,000 Points")
|
95 |
+
import plotly.graph_objects as go
|
96 |
+
import numpy as np
|
97 |
+
N = 1000000
|
98 |
+
fig = go.Figure()
|
99 |
+
fig.add_trace(
|
100 |
+
go.Scattergl(
|
101 |
+
x = np.random.randn(N),
|
102 |
+
y = np.random.randn(N),
|
103 |
+
mode = 'markers',
|
104 |
+
marker = dict(
|
105 |
+
line = dict(
|
106 |
+
width = 1,
|
107 |
+
color = 'DarkSlateGrey')
|
108 |
+
)
|
109 |
+
)
|
110 |
+
)
|
111 |
+
#fig.show()
|
112 |
+
st.plotly_chart(fig, use_container_width=True)
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
st.markdown("# WebGL Graph - ScatterGL")
|
117 |
+
fig = go.Figure()
|
118 |
+
trace_num = 10
|
119 |
+
point_num = 5000
|
120 |
+
for i in range(trace_num):
|
121 |
+
fig.add_trace(
|
122 |
+
go.Scattergl(
|
123 |
+
x = np.linspace(0, 1, point_num),
|
124 |
+
y = np.random.randn(point_num)+(i*5)
|
125 |
+
)
|
126 |
+
)
|
127 |
+
fig.update_layout(showlegend=False)
|
128 |
+
#fig.show()
|
129 |
+
st.plotly_chart(fig, use_container_width=True)
|
130 |
+
|
131 |
+
|
132 |
+
st.markdown("# Treemaps: https://plotly.com/python/treemaps/")
|
133 |
+
df = px.data.gapminder().query("year == 2007")
|
134 |
+
fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',
|
135 |
+
color='lifeExp', hover_data=['iso_alpha'],
|
136 |
+
color_continuous_scale='RdBu',
|
137 |
+
color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
|
138 |
+
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
|
139 |
+
#fig.show()
|
140 |
+
st.plotly_chart(fig, use_container_width=True)
|
141 |
+
|
142 |
+
|
143 |
+
st.markdown("# Sunburst: https://plotly.com/python/sunburst-charts/")
|
144 |
+
|
145 |
+
|
146 |
+
st.markdown("# Life Expectancy Sunburst")
|
147 |
+
df = px.data.gapminder().query("year == 2007")
|
148 |
+
fig = px.sunburst(df, path=['continent', 'country'], values='pop',
|
149 |
+
color='lifeExp', hover_data=['iso_alpha'],
|
150 |
+
color_continuous_scale='RdBu',
|
151 |
+
color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
|
152 |
+
st.plotly_chart(fig, use_container_width=True)
|
153 |
+
|
154 |
+
|
155 |
+
st.markdown("# Coffee Aromas and Tastes Sunburst")
|
156 |
+
df1 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/sunburst-coffee-flavors-complete.csv')
|
157 |
+
df2 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/coffee-flavors.csv')
|
158 |
+
fig = go.Figure()
|
159 |
+
fig.add_trace(go.Sunburst(
|
160 |
+
ids=df1.ids,
|
161 |
+
labels=df1.labels,
|
162 |
+
parents=df1.parents,
|
163 |
+
domain=dict(column=0)
|
164 |
+
))
|
165 |
+
fig.add_trace(go.Sunburst(
|
166 |
+
ids=df2.ids,
|
167 |
+
labels=df2.labels,
|
168 |
+
parents=df2.parents,
|
169 |
+
domain=dict(column=1),
|
170 |
+
maxdepth=2
|
171 |
+
))
|
172 |
+
fig.update_layout(
|
173 |
+
grid= dict(columns=2, rows=1),
|
174 |
+
margin = dict(t=0, l=0, r=0, b=0)
|
175 |
+
)
|
176 |
+
st.plotly_chart(fig, use_container_width=True)
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
|
181 |
+
|
182 |
+
# Sunburst
|
183 |
+
#data = dict(
|
184 |
+
# character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
|
185 |
+
# parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
|
186 |
+
# value=[10, 14, 12, 10, 2, 6, 6, 4, 4])
|
187 |
+
#fig = px.sunburst(
|
188 |
+
# data,
|
189 |
+
# names='character',
|
190 |
+
# parents='parent',
|
191 |
+
# values='value',
|
192 |
+
#)
|
193 |
+
#fig.show()
|
194 |
+
#st.plotly_chart(fig, use_container_width=True)
|
195 |
+
|
196 |
+
|
197 |
+
df = px.data.tips()
|
198 |
+
fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'],
|
199 |
+
values='total_bill', color='time',
|
200 |
+
color_discrete_map={'(?)':'lightgrey', 'Lunch':'gold', 'Dinner':'darkblue'})
|
201 |
+
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
|
202 |
+
#fig.show()
|
203 |
+
fig.update_traces(marker=dict(cornerradius=5))
|
204 |
+
|
205 |
+
st.plotly_chart(fig, use_container_width=True)
|
206 |
+
|
207 |
+
|
208 |
+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv')
|
209 |
+
fig = go.Figure(go.Treemap(
|
210 |
+
ids = df.ids,
|
211 |
+
labels = df.labels,
|
212 |
+
parents = df.parents,
|
213 |
+
pathbar_textfont_size=15,
|
214 |
+
root_color="lightgrey"
|
215 |
+
))
|
216 |
+
fig.update_layout(
|
217 |
+
uniformtext=dict(minsize=10, mode='hide'),
|
218 |
+
margin = dict(t=50, l=25, r=25, b=25)
|
219 |
+
)
|
220 |
+
#fig.show()
|
221 |
+
st.plotly_chart(fig, use_container_width=True)
|
222 |
+
|
223 |
+
|
224 |
+
df = pd.read_pickle('bloom_dataset.pkl')
|
225 |
+
fig = px.treemap(df, path=[px.Constant("ROOTS"), 'Macroarea', 'Family', 'Genus', 'Language', 'dataset_name'],
|
226 |
+
values='num_bytes', maxdepth=4)
|
227 |
+
fig.update_traces(root_color="pink")
|
228 |
+
fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
|
229 |
+
|
230 |
+
st.plotly_chart(fig, use_container_width=True)
|
bloom_dataset.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:27b17d22a1763de24c70da9ab87a6e6887cfdb7b17570e9758f4033217cbaf42
|
3 |
+
size 88499
|
requirements (1).txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
plotly
|
2 |
+
pandas
|
3 |
+
protobuf~=3.19.0
|