spatel54 commited on
Commit
c7c0484
·
verified ·
1 Parent(s): 5affa54

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +21 -15
src/streamlit_app.py CHANGED
@@ -163,13 +163,27 @@ df_top = df[df['crm_cd_desc'].isin(top_crimes)]
163
  heatmap1_data = df_top.groupby(['crm_cd_desc', 'year']).size().unstack(fill_value=0)
164
 
165
  # Create the heat map.
166
- plt.figure(figsize=(10, 6))
167
- sns.heatmap(heatmap1_data, annot=True, fmt="d", cmap="YlOrRd")
168
- plt.title("Top 10 Crime Types by Year")
169
- plt.xlabel("Year")
170
- plt.ylabel("Crime Type")
171
- plt.tight_layout()
172
- plt.show()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  ### Use this one!!!
175
  # Count the crime type and list out the top 10 crime type that have the most cases.
@@ -229,14 +243,6 @@ line_chart = alt.Chart(filtered_crimes).mark_line(point=True).encode(
229
  line_chart
230
 
231
  ### Use this one!!!
232
- # Load geojson file.
233
- gdf_counties = gpd.read_file("County_Boundary.geojson")
234
-
235
- # Creat dropdown menu.
236
- year_dropdown = ipywidgets.Dropdown(
237
- options= sorted(df['year'].unique()),
238
- description='Year:')
239
-
240
  # Identify top 10 crime types
241
  top_10_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index.tolist()
242
 
 
163
  heatmap1_data = df_top.groupby(['crm_cd_desc', 'year']).size().unstack(fill_value=0)
164
 
165
  # Create the heat map.
166
+ fig, ax = plt.subplots(figsize=(10, 6))
167
+
168
+ # 2. Draw into that Axes
169
+ sns.heatmap(
170
+ heatmap1_data,
171
+ annot=True,
172
+ fmt="d",
173
+ cmap="YlOrRd",
174
+ ax=ax
175
+ )
176
+
177
+ # 3. Set titles/labels on the Axes
178
+ ax.set_title("Top 10 Crime Types by Year")
179
+ ax.set_xlabel("Year")
180
+ ax.set_ylabel("Crime Type")
181
+
182
+ # 4. Tight layout
183
+ fig.tight_layout()
184
+
185
+ # 5. Render in Streamlit
186
+ st.pyplot(fig)
187
 
188
  ### Use this one!!!
189
  # Count the crime type and list out the top 10 crime type that have the most cases.
 
243
  line_chart
244
 
245
  ### Use this one!!!
 
 
 
 
 
 
 
 
246
  # Identify top 10 crime types
247
  top_10_crimes = df['crm_cd_desc'].value_counts().nlargest(10).index.tolist()
248