Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +8 -8
src/streamlit_app.py
CHANGED
|
@@ -254,7 +254,7 @@ st.pyplot(fig)
|
|
| 254 |
# Description.
|
| 255 |
st.markdown("""<div class="description">
|
| 256 |
This heatmap shows the frequency of the top 10 crimes from 2020 to 2025. The x axis is year and the y axis is crime type. The colormap is 'YlOrRd' to create a distinct visual difference in number of incidents. Dark red means that the incident frequency is high while light yellow means that the incident frequency is low. 'Vehicle Stolen' seems to be the most prevalent crime for all five years, given its values are highlighted in deeper shades of red. 'Vehicle Stolen' also seems to fluctuate between 20000 and 24000 throughout the five years. 'Thief of identity' also saw a spike in incident frequency for 2022, recording 21251 crimes. Limiting the heatmap to top 10 crimes addressed the most prominent crimes in LA. Since 2025 is not over, data for that year is still relatively inclusive. This visualization can help law enforcement easily detect trends of different crimes for a specific year. This data may allow them to predict future rates and be able to allocate resources accordingly to mitigate these crimes.
|
| 257 |
-
</div>""")
|
| 258 |
|
| 259 |
|
| 260 |
# -------------------------------- Plot 3: Line Chart --------------------------------
|
|
@@ -294,7 +294,7 @@ This plot is a line chart visualizing the annual number of incidents for the top
|
|
| 294 |
Each line represents a distinct crime type, allowing for easy comparison of trends across different categories.
|
| 295 |
The x-axis represents the year, the y-axis indicates the number of incidents, and a legend identifies the color corresponding to each specific
|
| 296 |
crime type: Battery - Simple Assault, Burglary From Vehicle, Theft of Identity, Vandalism - Felony , and Vehicle - Stolen. The plot highlights
|
| 297 |
-
the fluctuations and overall trajectories of these major crime categories across the years.</div>""")
|
| 298 |
|
| 299 |
|
| 300 |
# -------------------------------- Plot 4: Map --------------------------------
|
|
@@ -359,9 +359,9 @@ for _, row in df_filtered.iterrows():
|
|
| 359 |
st_folium(new_map, width=1000, height=800)
|
| 360 |
|
| 361 |
# Description.
|
| 362 |
-
st.markdown("""
|
| 363 |
This visualization uses Folium to build an interactive map of crime distribution in Los Angeles, highlighting the geospatial clustering characteristics of different years and crime types, and emphasizing the user's experience of freely exploring the map. The base map uses real streets and geographic backgrounds to enhance the spatial visualization of the image. The map shows the administrative boundaries of Los Angeles County in blue polygons, which are loaded with GeoJSON data and overlaid on the map to specify the geographic boundaries of crime locations. The red dots on the map represent the location of individual crimes, and the system samples no more than 300 data items from this category for visualization, with each dot pinpointed by latitude and longitude coordinates. The map supports full Leaflet.js functionality, including zooming, dragging, layer control, and other operations, which greatly enhances the flexibility of data exploration. A drop-down menu in the upper left corner of the page allows users to customize filters for specific years and crime types, enabling instant updates to the map content.
|
| 364 |
-
""")
|
| 365 |
|
| 366 |
# -------------------------------- Plot 4: Stacked Bar Chart --------------------------------
|
| 367 |
# Group by crime type and year.
|
|
@@ -383,11 +383,11 @@ bar_chart = alt.Chart(stacked_year_df).mark_bar().encode(
|
|
| 383 |
st.altair_chart(bar_chart, use_container_width=True)
|
| 384 |
|
| 385 |
# Description.
|
| 386 |
-
st.markdown("""
|
| 387 |
Description: Our stacked bar chart shows the number of reported crimes for the top 10 most common crime types from 2020 to 2024. Each bar represents a year, and the different colors in the bars show different types of crimes, like stolen vehicles, burglary, vandalism, and assault. The taller the colored section, the more incidents of that crime there were in that year.
|
| 388 |
|
| 389 |
By observing the plot, we can find out that 2022 had the most crimes, the year had the second most crimes is 2023, and etc. Besides that, we can also find out that some crimes, like vehicle theft, petty theft, and burglary from vehicles, happened a lot every year and make up a big part of the total.
|
| 390 |
-
""")
|
| 391 |
|
| 392 |
# -------------------------------- Plot 5: Bar Chart --------------------------------
|
| 393 |
# Group by crime type and year.
|
|
@@ -417,6 +417,6 @@ barchart = alt.Chart(heatmap1_df).mark_bar().encode(
|
|
| 417 |
barchart
|
| 418 |
|
| 419 |
# Description.
|
| 420 |
-
st.markdown(""" This interactive bar chart allows users to explore the most frequently reported crime types in Los Angeles by year. By adjusting the slider below the chart, the visualization updates in real time to show the top ten crime categories for the selected year. Each bar represents the total number of incidents, with color coding used to distinguish different crime types and a legend on the right for reference.
|
| 421 |
This visualization makes it easy to compare how the composition of major crime types evolves over time and to detect emerging issues that may require further investigation or policy response.
|
| 422 |
-
""")
|
|
|
|
| 254 |
# Description.
|
| 255 |
st.markdown("""<div class="description">
|
| 256 |
This heatmap shows the frequency of the top 10 crimes from 2020 to 2025. The x axis is year and the y axis is crime type. The colormap is 'YlOrRd' to create a distinct visual difference in number of incidents. Dark red means that the incident frequency is high while light yellow means that the incident frequency is low. 'Vehicle Stolen' seems to be the most prevalent crime for all five years, given its values are highlighted in deeper shades of red. 'Vehicle Stolen' also seems to fluctuate between 20000 and 24000 throughout the five years. 'Thief of identity' also saw a spike in incident frequency for 2022, recording 21251 crimes. Limiting the heatmap to top 10 crimes addressed the most prominent crimes in LA. Since 2025 is not over, data for that year is still relatively inclusive. This visualization can help law enforcement easily detect trends of different crimes for a specific year. This data may allow them to predict future rates and be able to allocate resources accordingly to mitigate these crimes.
|
| 257 |
+
</div>""",unsafe_allow_html=True)
|
| 258 |
|
| 259 |
|
| 260 |
# -------------------------------- Plot 3: Line Chart --------------------------------
|
|
|
|
| 294 |
Each line represents a distinct crime type, allowing for easy comparison of trends across different categories.
|
| 295 |
The x-axis represents the year, the y-axis indicates the number of incidents, and a legend identifies the color corresponding to each specific
|
| 296 |
crime type: Battery - Simple Assault, Burglary From Vehicle, Theft of Identity, Vandalism - Felony , and Vehicle - Stolen. The plot highlights
|
| 297 |
+
the fluctuations and overall trajectories of these major crime categories across the years.</div>""",unsafe_allow_html=True)
|
| 298 |
|
| 299 |
|
| 300 |
# -------------------------------- Plot 4: Map --------------------------------
|
|
|
|
| 359 |
st_folium(new_map, width=1000, height=800)
|
| 360 |
|
| 361 |
# Description.
|
| 362 |
+
st.markdown("""<div class="description">
|
| 363 |
This visualization uses Folium to build an interactive map of crime distribution in Los Angeles, highlighting the geospatial clustering characteristics of different years and crime types, and emphasizing the user's experience of freely exploring the map. The base map uses real streets and geographic backgrounds to enhance the spatial visualization of the image. The map shows the administrative boundaries of Los Angeles County in blue polygons, which are loaded with GeoJSON data and overlaid on the map to specify the geographic boundaries of crime locations. The red dots on the map represent the location of individual crimes, and the system samples no more than 300 data items from this category for visualization, with each dot pinpointed by latitude and longitude coordinates. The map supports full Leaflet.js functionality, including zooming, dragging, layer control, and other operations, which greatly enhances the flexibility of data exploration. A drop-down menu in the upper left corner of the page allows users to customize filters for specific years and crime types, enabling instant updates to the map content.
|
| 364 |
+
</div>""",unsafe_allow_html=True)
|
| 365 |
|
| 366 |
# -------------------------------- Plot 4: Stacked Bar Chart --------------------------------
|
| 367 |
# Group by crime type and year.
|
|
|
|
| 383 |
st.altair_chart(bar_chart, use_container_width=True)
|
| 384 |
|
| 385 |
# Description.
|
| 386 |
+
st.markdown("""<div class="description">
|
| 387 |
Description: Our stacked bar chart shows the number of reported crimes for the top 10 most common crime types from 2020 to 2024. Each bar represents a year, and the different colors in the bars show different types of crimes, like stolen vehicles, burglary, vandalism, and assault. The taller the colored section, the more incidents of that crime there were in that year.
|
| 388 |
|
| 389 |
By observing the plot, we can find out that 2022 had the most crimes, the year had the second most crimes is 2023, and etc. Besides that, we can also find out that some crimes, like vehicle theft, petty theft, and burglary from vehicles, happened a lot every year and make up a big part of the total.
|
| 390 |
+
</div>""",unsafe_allow_html=True)
|
| 391 |
|
| 392 |
# -------------------------------- Plot 5: Bar Chart --------------------------------
|
| 393 |
# Group by crime type and year.
|
|
|
|
| 417 |
barchart
|
| 418 |
|
| 419 |
# Description.
|
| 420 |
+
st.markdown("""<div class="description"> This interactive bar chart allows users to explore the most frequently reported crime types in Los Angeles by year. By adjusting the slider below the chart, the visualization updates in real time to show the top ten crime categories for the selected year. Each bar represents the total number of incidents, with color coding used to distinguish different crime types and a legend on the right for reference.
|
| 421 |
This visualization makes it easy to compare how the composition of major crime types evolves over time and to detect emerging issues that may require further investigation or policy response.
|
| 422 |
+
</div>""",unsafe_allow_html=True)
|