AAhad commited on
Commit
672c30d
·
verified ·
1 Parent(s): aadbd6a

updated logic

Browse files
Files changed (1) hide show
  1. app.py +317 -14
app.py CHANGED
@@ -1,20 +1,323 @@
1
  import streamlit as st
2
- import numpy as np
3
- import plotly.figure_factory as ff
 
4
 
5
- # Add histogram data
6
- x1 = np.random.randn(200) - 2
7
- x2 = np.random.randn(200)
8
- x3 = np.random.randn(200) + 2
 
 
 
 
 
 
 
 
 
9
 
10
- # Group data together
11
- hist_data = [x1, x2, x3]
 
 
 
12
 
13
- group_labels = ['Group 1', 'Group 2', 'Group 3']
14
 
15
- # Create distplot with custom bin_size
16
- fig = ff.create_distplot(
17
- hist_data, group_labels, bin_size=[.1, .25, .5])
18
 
19
- # Plot!
20
- st.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import plotly.express as px
3
+ import plotly.graph_objects as go
4
+ import inspect
5
 
6
+ @st.experimental_memo
7
+ def get_chart_29333332():
8
+ import plotly.express as px
9
+
10
+ fig = px.imshow([[1, 20, 30],
11
+ [20, 1, 60],
12
+ [30, 60, 1]])
13
+
14
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
15
+ with tab1:
16
+ st.plotly_chart(fig, theme="streamlit")
17
+ with tab2:
18
+ st.plotly_chart(fig, theme=None)
19
 
20
+ try:
21
+ st.expander("See code").code(inspect.getsource(get_chart_29333332))
22
+ get_chart_29333332()
23
+ except Exception as e:
24
+ st.exception(e)
25
 
 
26
 
 
 
 
27
 
28
+ @st.experimental_memo
29
+ def get_chart_41983230():
30
+ import plotly.express as px
31
+
32
+ df = px.data.medals_wide(indexed=True)
33
+ fig = px.imshow(df)
34
+
35
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
36
+ with tab1:
37
+ st.plotly_chart(fig, theme="streamlit")
38
+ with tab2:
39
+ st.plotly_chart(fig, theme=None)
40
+
41
+ try:
42
+ st.expander("See code").code(inspect.getsource(get_chart_41983230))
43
+ get_chart_41983230()
44
+ except Exception as e:
45
+ st.exception(e)
46
+
47
+
48
+
49
+ @st.experimental_memo
50
+ def get_chart_8045850():
51
+ import plotly.express as px
52
+
53
+ z = [[.1, .3, .5, .7, .9],
54
+ [1, .8, .6, .4, .2],
55
+ [.2, 0, .5, .7, .9],
56
+ [.9, .8, .4, .2, 0],
57
+ [.3, .4, .5, .7, 1]]
58
+
59
+ fig = px.imshow(z, text_auto=True)
60
+
61
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
62
+ with tab1:
63
+ st.plotly_chart(fig, theme="streamlit")
64
+ with tab2:
65
+ st.plotly_chart(fig, theme=None)
66
+
67
+ try:
68
+ st.expander("See code").code(inspect.getsource(get_chart_8045850))
69
+ get_chart_8045850()
70
+ except Exception as e:
71
+ st.exception(e)
72
+
73
+
74
+
75
+ @st.experimental_memo
76
+ def get_chart_79075482():
77
+ import plotly.express as px
78
+
79
+ z = [[.1, .3, .5, .7, .9],
80
+ [1, .8, .6, .4, .2],
81
+ [.2, 0, .5, .7, .9],
82
+ [.9, .8, .4, .2, 0],
83
+ [.3, .4, .5, .7, 1]]
84
+
85
+ fig = px.imshow(z, text_auto=True, aspect="auto")
86
+
87
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
88
+ with tab1:
89
+ st.plotly_chart(fig, theme="streamlit")
90
+ with tab2:
91
+ st.plotly_chart(fig, theme=None)
92
+
93
+ try:
94
+ st.expander("See code").code(inspect.getsource(get_chart_79075482))
95
+ get_chart_79075482()
96
+ except Exception as e:
97
+ st.exception(e)
98
+
99
+
100
+
101
+ @st.experimental_memo
102
+ def get_chart_12486592():
103
+ import plotly.express as px
104
+ data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
105
+ fig = px.imshow(data,
106
+ labels=dict(x="Day of Week", y="Time of Day", color="Productivity"),
107
+ x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
108
+ y=['Morning', 'Afternoon', 'Evening']
109
+ )
110
+ fig.update_xaxes(side="top")
111
+
112
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
113
+ with tab1:
114
+ st.plotly_chart(fig, theme="streamlit")
115
+ with tab2:
116
+ st.plotly_chart(fig, theme=None)
117
+
118
+ try:
119
+ st.expander("See code").code(inspect.getsource(get_chart_12486592))
120
+ get_chart_12486592()
121
+ except Exception as e:
122
+ st.exception(e)
123
+
124
+
125
+
126
+ @st.experimental_memo
127
+ def get_chart_63882696():
128
+ import plotly.express as px
129
+ import xarray as xr
130
+ # Load xarray from dataset included in the xarray tutorial
131
+ airtemps = xr.tutorial.open_dataset('air_temperature').air.sel(lon=250.0)
132
+ fig = px.imshow(airtemps.T, color_continuous_scale='RdBu_r', origin='lower')
133
+
134
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
135
+ with tab1:
136
+ st.plotly_chart(fig, theme="streamlit")
137
+ with tab2:
138
+ st.plotly_chart(fig, theme=None)
139
+
140
+ try:
141
+ st.expander("See code").code(inspect.getsource(get_chart_63882696))
142
+ get_chart_63882696()
143
+ except Exception as e:
144
+ st.exception(e)
145
+
146
+
147
+
148
+ @st.experimental_memo
149
+ def get_chart_97846046():
150
+ import plotly.graph_objects as go
151
+
152
+ fig = go.Figure(data=go.Heatmap(
153
+ z=[[1, 20, 30],
154
+ [20, 1, 60],
155
+ [30, 60, 1]]))
156
+
157
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
158
+ with tab1:
159
+ st.plotly_chart(fig, theme="streamlit")
160
+ with tab2:
161
+ st.plotly_chart(fig, theme=None)
162
+
163
+ try:
164
+ st.expander("See code").code(inspect.getsource(get_chart_97846046))
165
+ get_chart_97846046()
166
+ except Exception as e:
167
+ st.exception(e)
168
+
169
+
170
+
171
+ @st.experimental_memo
172
+ def get_chart_37340223():
173
+ import plotly.graph_objects as go
174
+
175
+ fig = go.Figure(data=go.Heatmap(
176
+ z=[[1, None, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
177
+ x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
178
+ y=['Morning', 'Afternoon', 'Evening'],
179
+ hoverongaps = False))
180
+
181
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
182
+ with tab1:
183
+ st.plotly_chart(fig, theme="streamlit")
184
+ with tab2:
185
+ st.plotly_chart(fig, theme=None)
186
+
187
+ try:
188
+ st.expander("See code").code(inspect.getsource(get_chart_37340223))
189
+ get_chart_37340223()
190
+ except Exception as e:
191
+ st.exception(e)
192
+
193
+
194
+
195
+ @st.experimental_memo
196
+ def get_chart_20250490():
197
+ import plotly.graph_objects as go
198
+ import numpy as np
199
+
200
+ # Build the rectangles as a heatmap
201
+ # specify the edges of the heatmap squares
202
+ phi = (1 + np.sqrt(5) )/2. # golden ratio
203
+ xe = [0, 1, 1+(1/(phi**4)), 1+(1/(phi**3)), phi]
204
+ ye = [0, 1/(phi**3), 1/phi**3+1/phi**4, 1/(phi**2), 1]
205
+
206
+ z = [ [13,3,3,5],
207
+ [13,2,1,5],
208
+ [13,10,11,12],
209
+ [13,8,8,8]
210
+ ]
211
+
212
+ fig = go.Figure(data=go.Heatmap(
213
+ x = np.sort(xe),
214
+ y = np.sort(ye),
215
+ z = z,
216
+ type = 'heatmap',
217
+ colorscale = 'Viridis'))
218
+
219
+ # Add spiral line plot
220
+
221
+ def spiral(th):
222
+ a = 1.120529
223
+ b = 0.306349
224
+ r = a*np.exp(-b*th)
225
+ return (r*np.cos(th), r*np.sin(th))
226
+
227
+ theta = np.linspace(-np.pi/13,4*np.pi,1000); # angle
228
+ (x,y) = spiral(theta)
229
+
230
+ fig.add_trace(go.Scatter(x= -x+x[0], y= y-y[0],
231
+ line =dict(color='white',width=3)))
232
+
233
+ axis_template = dict(range = [0,1.6], autorange = False,
234
+ showgrid = False, zeroline = False,
235
+ linecolor = 'black', showticklabels = False,
236
+ ticks = '' )
237
+
238
+ fig.update_layout(margin = dict(t=200,r=200,b=200,l=200),
239
+ xaxis = axis_template,
240
+ yaxis = axis_template,
241
+ showlegend = False,
242
+ width = 700, height = 700,
243
+ autosize = False )
244
+
245
+
246
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
247
+ with tab1:
248
+ st.plotly_chart(fig, theme="streamlit")
249
+ with tab2:
250
+ st.plotly_chart(fig, theme=None)
251
+
252
+ try:
253
+ st.expander("See code").code(inspect.getsource(get_chart_20250490))
254
+ get_chart_20250490()
255
+ except Exception as e:
256
+ st.exception(e)
257
+
258
+
259
+
260
+ @st.experimental_memo
261
+ def get_chart_54456624():
262
+ import plotly.graph_objects as go
263
+ import datetime
264
+ import numpy as np
265
+ np.random.seed(1)
266
+
267
+ programmers = ['Alex','Nicole','Sara','Etienne','Chelsea','Jody','Marianne']
268
+
269
+ base = datetime.datetime.today()
270
+ dates = base - np.arange(180) * datetime.timedelta(days=1)
271
+ z = np.random.poisson(size=(len(programmers), len(dates)))
272
+
273
+ fig = go.Figure(data=go.Heatmap(
274
+ z=z,
275
+ x=dates,
276
+ y=programmers,
277
+ colorscale='Viridis'))
278
+
279
+ fig.update_layout(
280
+ title='GitHub commits per day',
281
+ xaxis_nticks=36)
282
+
283
+
284
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
285
+ with tab1:
286
+ st.plotly_chart(fig, theme="streamlit")
287
+ with tab2:
288
+ st.plotly_chart(fig, theme=None)
289
+
290
+ try:
291
+ st.expander("See code").code(inspect.getsource(get_chart_54456624))
292
+ get_chart_54456624()
293
+ except Exception as e:
294
+ st.exception(e)
295
+
296
+
297
+
298
+ @st.experimental_memo
299
+ def get_chart_69344836():
300
+ import plotly.graph_objects as go
301
+
302
+ fig = go.Figure(data=go.Heatmap(
303
+ z=[[1, 20, 30],
304
+ [20, 1, 60],
305
+ [30, 60, 1]],
306
+ text=[['one', 'twenty', 'thirty'],
307
+ ['twenty', 'one', 'sixty'],
308
+ ['thirty', 'sixty', 'one']],
309
+ texttemplate="%{text}",
310
+ textfont={"size":20}))
311
+
312
+
313
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
314
+ with tab1:
315
+ st.plotly_chart(fig, theme="streamlit")
316
+ with tab2:
317
+ st.plotly_chart(fig, theme=None)
318
+
319
+ try:
320
+ st.expander("See code").code(inspect.getsource(get_chart_69344836))
321
+ get_chart_69344836()
322
+ except Exception as e:
323
+ st.exception(e)