wen11235 commited on
Commit
3c95e1f
·
verified ·
1 Parent(s): 1535d87

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +33 -1
src/streamlit_app.py CHANGED
@@ -306,4 +306,36 @@ bar_chart = alt.Chart(stacked_year_df).mark_bar().encode(
306
  title='Stacked Crime Composition by Year (Top 10 Crime Types)'
307
  )
308
 
309
- st.altair_chart(bar_chart, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  title='Stacked Crime Composition by Year (Top 10 Crime Types)'
307
  )
308
 
309
+ st.altair_chart(bar_chart, use_container_width=True)
310
+
311
+
312
+
313
+
314
+ top_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index
315
+ df_top = df[df['crm_cd_desc'].isin(top_crimes)]
316
+
317
+ # Group by crime type and year.
318
+ heatmap1_df = df_top.groupby(['crm_cd_desc', 'year']).size().reset_index(name='count')
319
+
320
+ # Create the slider based on the previous heatmap.
321
+ year_slider = alt.binding_range(min=heatmap1_df['year'].min(), max=heatmap1_df['year'].max(), step=1)
322
+ year_select = alt.selection_point(fields=['year'], bind=year_slider, name="Select")
323
+
324
+ # Convert the heatmap into bar chart.
325
+ heatmap1 = alt.Chart(heatmap1_df).mark_bar().encode(
326
+ x=alt.X('crm_cd_desc:N', title='Crime Type', sort='-y'),
327
+ y=alt.Y('count:Q', title='Number of Incidents'),
328
+ color=alt.Color('crm_cd_desc:N', title='Crime Type'),
329
+ tooltip=['crm_cd_desc', 'count']
330
+ ).transform_filter(
331
+ year_select
332
+ ).add_params(
333
+ year_select
334
+ ).properties(
335
+ width=600,
336
+ height=400,
337
+ title='Top 10 Crime Types (Filtered by Year)'
338
+ )
339
+
340
+ # Display the plot.
341
+ heatmap1