namdini commited on
Commit
9d270e5
·
verified ·
1 Parent(s): 5918811

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -7,6 +7,17 @@ from streamlit_plotly_events import plotly_events
7
  from folium.plugins import HeatMap, MarkerCluster
8
  from streamlit_folium import st_folium
9
 
 
 
 
 
 
 
 
 
 
 
 
10
  @st.cache_data
11
  def load_and_preprocess_data(file_path):
12
  # Read the data
@@ -71,7 +82,7 @@ def create_severity_violation_chart(df, age_group=None):
71
  title=f'Crash Severity Distribution by Violation Type - {age_group}',
72
  labels={'count': 'Number of Incidents', 'Violation': 'Violation Type'},
73
  height=600,
74
- color_discrete_sequence=px.colors.qualitative.Set1 # --> for part 3
75
  )
76
 
77
  fig.update_layout(
@@ -94,7 +105,8 @@ def create_interactive_pie_chart(violations, selected_violation):
94
  names='Severity',
95
  values='count',
96
  title=f'Severity Level Distribution for Violation: {selected_violation}',
97
- height=400
 
98
  )
99
 
100
  return fig
 
7
  from folium.plugins import HeatMap, MarkerCluster
8
  from streamlit_folium import st_folium
9
 
10
+ # To fix the color scheme in crash stats plot
11
+ severity_colors = {
12
+ "No Injury": "#1f77b4",
13
+ "Possible Injury": "#aec7e8",
14
+ "Non Incapacitating Injury": "#ff7f0e",
15
+ "Incapacitating Injury": "#ffbb78",
16
+ "Suspected Minor Injury": "#2ca02c",
17
+ "Suspected Serious Injury": "#98df8a",
18
+ "Fatal": "#d62728",
19
+ }
20
+
21
  @st.cache_data
22
  def load_and_preprocess_data(file_path):
23
  # Read the data
 
82
  title=f'Crash Severity Distribution by Violation Type - {age_group}',
83
  labels={'count': 'Number of Incidents', 'Violation': 'Violation Type'},
84
  height=600,
85
+ color_discrete_map=severity_colors # --> for part 3
86
  )
87
 
88
  fig.update_layout(
 
105
  names='Severity',
106
  values='count',
107
  title=f'Severity Level Distribution for Violation: {selected_violation}',
108
+ height=400,
109
+ color_discrete_map=severity_colors
110
  )
111
 
112
  return fig