JanhaviZarapkar commited on
Commit
f173071
·
verified ·
1 Parent(s): a334da9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py CHANGED
@@ -178,3 +178,61 @@ st.markdown("""
178
  **~By Janhavi Tushar Zarapkar**
179
  """, unsafe_allow_html=True)
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  **~By Janhavi Tushar Zarapkar**
179
  """, unsafe_allow_html=True)
180
 
181
+ from vega_datasets import data
182
+ source = data.seattle_weather()
183
+
184
+ scale = alt.Scale(
185
+ domain=["sun", "fog", "drizzle", "rain", "snow"],
186
+ range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
187
+ )
188
+ color = alt.Color("weather:N", scale=scale)
189
+
190
+ # We create two selections:
191
+ # - a brush that is active on the top panel
192
+ # - a multi-click that is active on the bottom panel
193
+ brush = alt.selection_interval(encodings=["x"])
194
+ click = alt.selection_point(encodings=["color"])
195
+
196
+ # Top panel is scatter plot of temperature vs time
197
+ points = (
198
+ alt.Chart()
199
+ .mark_point()
200
+ .encode(
201
+ alt.X("monthdate(date):T", title="Date (Month Year)"),
202
+ alt.Y(
203
+ "temp_max:Q",
204
+ title="Maximum Daily Temperature (C)",
205
+ scale=alt.Scale(domain=[-5, 40]),
206
+ ),
207
+ color=alt.condition(brush, color, alt.value("lightgray")),
208
+ size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
209
+ )
210
+ .properties(width=550, height=300)
211
+ .add_params(brush)
212
+ .transform_filter(click)
213
+ )
214
+
215
+ # Bottom panel is a bar chart of weather type
216
+ bars = (
217
+ alt.Chart()
218
+ .mark_bar()
219
+ .encode(
220
+ x="count()",
221
+ y="weather:N",
222
+ color=alt.condition(click, color, alt.value("lightgray")),
223
+ )
224
+ .transform_filter(brush)
225
+ .properties(
226
+ width=550,
227
+ )
228
+ .add_params(click)
229
+ )
230
+
231
+ chart = alt.vconcat(points, bars, data=source, title="Seattle Weather - 2000 to 2010")
232
+
233
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
234
+
235
+ with tab1:
236
+ st.altair_chart(chart, theme="streamlit", use_container_width=True)
237
+ with tab2:
238
+ st.altair_chart(chart, theme=None, use_container_width=True)