Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -25
src/streamlit_app.py
CHANGED
|
@@ -87,37 +87,36 @@ chart1 = (
|
|
| 87 |
.properties(width=400, height=400, title="Top 10 Crime Types")
|
| 88 |
)
|
| 89 |
st.altair_chart(chart1, use_container_width=True)
|
| 90 |
-
|
| 91 |
-
#
|
| 92 |
base = (
|
| 93 |
alt.Chart(top_crimes)
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
)
|
| 105 |
|
| 106 |
-
#
|
| 107 |
labels = (
|
| 108 |
alt.Chart(top_crimes)
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
)
|
| 115 |
|
| 116 |
-
#
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
|
| 120 |
-
col1, col2, col3 = st.columns([1, 2, 1])
|
| 121 |
-
with col2:
|
| 122 |
-
st.altair_chart(pie, use_container_width=False)
|
| 123 |
-
|
|
|
|
| 87 |
.properties(width=400, height=400, title="Top 10 Crime Types")
|
| 88 |
)
|
| 89 |
st.altair_chart(chart1, use_container_width=True)
|
| 90 |
+
|
| 91 |
+
# Base pie chart (innerRadius=50 gives us the donut)
|
| 92 |
base = (
|
| 93 |
alt.Chart(top_crimes)
|
| 94 |
+
.mark_arc(innerRadius=50)
|
| 95 |
+
.encode(
|
| 96 |
+
theta=alt.Theta("Count:Q"),
|
| 97 |
+
color=alt.Color("Crime Type:N", legend=alt.Legend(title="Crime Type")),
|
| 98 |
+
tooltip=[
|
| 99 |
+
alt.Tooltip("Crime Type:N"),
|
| 100 |
+
alt.Tooltip("Count:Q"),
|
| 101 |
+
alt.Tooltip("Percentage:Q", format=".1%")
|
| 102 |
+
]
|
| 103 |
+
)
|
| 104 |
)
|
| 105 |
|
| 106 |
+
# Add labels *outside* each slice by using a larger radius
|
| 107 |
labels = (
|
| 108 |
alt.Chart(top_crimes)
|
| 109 |
+
.mark_text(radius=120, size=11, fontWeight="bold")
|
| 110 |
+
.encode(
|
| 111 |
+
theta=alt.Theta("Count:Q"),
|
| 112 |
+
text=alt.Text("Crime Type:N")
|
| 113 |
+
)
|
| 114 |
)
|
| 115 |
|
| 116 |
+
# Combine and set size/title
|
| 117 |
+
chart2 = (
|
| 118 |
+
(base + labels)
|
| 119 |
+
.properties(width=600, height=600, title="Top 10 Crime Types")
|
| 120 |
+
)
|
| 121 |
|
| 122 |
+
st.altair_chart(chart2, use_container_width=False)
|
|
|
|
|
|
|
|
|
|
|
|