awacke1 commited on
Commit
4ab5104
·
1 Parent(s): 2970f7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -11
app.py CHANGED
@@ -6,6 +6,44 @@ import plotly.graph_objects as go
6
 
7
  st.set_page_config(page_title="Plotly Graphing Libraries",layout='wide')
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  st.markdown("# Treemaps: https://plotly.com/python/treemaps/")
10
  df = px.data.gapminder().query("year == 2007")
11
  fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',
@@ -18,20 +56,59 @@ st.plotly_chart(fig, use_container_width=True)
18
 
19
 
20
  st.markdown("# Sunburst: https://plotly.com/python/sunburst-charts/")
21
- data = dict(
22
- character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
23
- parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
24
- value=[10, 14, 12, 10, 2, 6, 6, 4, 4])
25
- fig = px.sunburst(
26
- data,
27
- names='character',
28
- parents='parent',
29
- values='value',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  )
31
- #fig.show()
32
  st.plotly_chart(fig, use_container_width=True)
33
 
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  df = px.data.tips()
36
  fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'],
37
  values='total_bill', color='time',
@@ -43,7 +120,6 @@ fig.update_traces(marker=dict(cornerradius=5))
43
  st.plotly_chart(fig, use_container_width=True)
44
 
45
 
46
-
47
  df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv')
48
  fig = go.Figure(go.Treemap(
49
  ids = df.ids,
 
6
 
7
  st.set_page_config(page_title="Plotly Graphing Libraries",layout='wide')
8
 
9
+
10
+ st.markdown("# WebGL with many gifts, traces")
11
+ fig = go.Figure()
12
+ trace_num = 10
13
+ point_num = 5000
14
+ for i in range(trace_num):
15
+ fig.add_trace(
16
+ go.Scattergl(
17
+ x = np.linspace(0, 1, point_num),
18
+ y = np.random.randn(point_num)+(i*5)
19
+ )
20
+ )
21
+ fig.update_layout(showlegend=False)
22
+ #fig.show()
23
+ st.plotly_chart(fig, use_container_width=True)
24
+
25
+
26
+ st.markdown("WebGL Rendering with 1,000,000 Points")
27
+ import plotly.graph_objects as go
28
+ import numpy as np
29
+ N = 1000000
30
+ fig = go.Figure()
31
+ fig.add_trace(
32
+ go.Scattergl(
33
+ x = np.random.randn(N),
34
+ y = np.random.randn(N),
35
+ mode = 'markers',
36
+ marker = dict(
37
+ line = dict(
38
+ width = 1,
39
+ color = 'DarkSlateGrey')
40
+ )
41
+ )
42
+ )
43
+ #fig.show()
44
+ st.plotly_chart(fig, use_container_width=True)
45
+
46
+
47
  st.markdown("# Treemaps: https://plotly.com/python/treemaps/")
48
  df = px.data.gapminder().query("year == 2007")
49
  fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], values='pop',
 
56
 
57
 
58
  st.markdown("# Sunburst: https://plotly.com/python/sunburst-charts/")
59
+
60
+
61
+ st.markdown("# Life Expectancy Sunburst")
62
+ df = px.data.gapminder().query("year == 2007")
63
+ fig = px.sunburst(df, path=['continent', 'country'], values='pop',
64
+ color='lifeExp', hover_data=['iso_alpha'],
65
+ color_continuous_scale='RdBu',
66
+ color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
67
+ st.plotly_chart(fig, use_container_width=True)
68
+
69
+
70
+ st.markdown("# Coffee Aromas and Tastes Sunburst")
71
+ df1 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/sunburst-coffee-flavors-complete.csv')
72
+ df2 = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/718417069ead87650b90472464c7565dc8c2cb1c/coffee-flavors.csv')
73
+ fig = go.Figure()
74
+ fig.add_trace(go.Sunburst(
75
+ ids=df1.ids,
76
+ labels=df1.labels,
77
+ parents=df1.parents,
78
+ domain=dict(column=0)
79
+ ))
80
+ fig.add_trace(go.Sunburst(
81
+ ids=df2.ids,
82
+ labels=df2.labels,
83
+ parents=df2.parents,
84
+ domain=dict(column=1),
85
+ maxdepth=2
86
+ ))
87
+ fig.update_layout(
88
+ grid= dict(columns=2, rows=1),
89
+ margin = dict(t=0, l=0, r=0, b=0)
90
  )
 
91
  st.plotly_chart(fig, use_container_width=True)
92
 
93
 
94
+
95
+
96
+
97
+ # Sunburst
98
+ #data = dict(
99
+ # character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
100
+ # parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
101
+ # value=[10, 14, 12, 10, 2, 6, 6, 4, 4])
102
+ #fig = px.sunburst(
103
+ # data,
104
+ # names='character',
105
+ # parents='parent',
106
+ # values='value',
107
+ #)
108
+ #fig.show()
109
+ #st.plotly_chart(fig, use_container_width=True)
110
+
111
+
112
  df = px.data.tips()
113
  fig = px.treemap(df, path=[px.Constant("all"), 'sex', 'day', 'time'],
114
  values='total_bill', color='time',
 
120
  st.plotly_chart(fig, use_container_width=True)
121
 
122
 
 
123
  df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv')
124
  fig = go.Figure(go.Treemap(
125
  ids = df.ids,