Spaces:
Sleeping
Sleeping
Commit
·
b930636
1
Parent(s):
973b43e
modify pages
Browse files
Home.py
CHANGED
@@ -48,16 +48,16 @@ def create_discontinuous_colormap(n_colors):
|
|
48 |
colors = [cmap(i / (n_colors - 1)) for i in range(n_colors)]
|
49 |
return mcolors.ListedColormap(colors)
|
50 |
|
51 |
-
def create_colormap_legend(vmin, vmax, cmap, n_colors
|
52 |
fig, ax = plt.subplots(figsize=(6, 0.8))
|
53 |
fig.subplots_adjust(bottom=0.5)
|
54 |
|
55 |
bounds = np.linspace(vmin, vmax, n_colors + 1)
|
56 |
norm = mcolors.BoundaryNorm(bounds, cmap.N)
|
57 |
cbar = fig.colorbar(plt.cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation='horizontal',
|
58 |
-
spacing='proportional', boundaries=bounds, format='%.
|
59 |
cbar.set_ticks(bounds)
|
60 |
-
ax.set_title(
|
61 |
|
62 |
buf = io.BytesIO()
|
63 |
plt.savefig(buf, format='png', dpi=300, bbox_inches='tight')
|
@@ -82,6 +82,9 @@ def app():
|
|
82 |
st.error("Failed to load data. Please try again later.")
|
83 |
return
|
84 |
|
|
|
|
|
|
|
85 |
# City filter
|
86 |
cities = sorted(gdf['CITY_NAME'].unique().tolist())
|
87 |
selected_cities = st.multiselect("市区町村", cities, default=[])
|
@@ -92,8 +95,7 @@ def app():
|
|
92 |
else:
|
93 |
gdf_filtered = gdf
|
94 |
|
95 |
-
selected_attribute = "
|
96 |
-
selected_attribute_jp = "緑被率"
|
97 |
|
98 |
# Custom CSS to create a box around the color scale controls
|
99 |
st.markdown("""
|
@@ -109,16 +111,16 @@ def app():
|
|
109 |
|
110 |
# Color scale controls in an expander
|
111 |
with st.expander("カラースケール設定", expanded=True):
|
112 |
-
|
113 |
col1, col2, col3, col4 = st.columns(4)
|
114 |
with col1:
|
115 |
n_colors = st.slider("分割数", min_value=2, max_value=20, value=5)
|
116 |
with col2:
|
117 |
alpha = st.slider("透過率", min_value=0.0, max_value=1.0, value=0.8, step=0.1)
|
118 |
with col3:
|
119 |
-
vmin = st.number_input("最小値", value=0.0, step=0
|
120 |
with col4:
|
121 |
-
vmax = st.number_input("最大値", value=
|
122 |
st.markdown('</div>', unsafe_allow_html=True)
|
123 |
|
124 |
# Other controls
|
@@ -174,13 +176,13 @@ def app():
|
|
174 |
layers=[layer],
|
175 |
initial_view_state=view_state,
|
176 |
map_style="mapbox://styles/mapbox/light-v9",
|
177 |
-
tooltip={"text": "{CITY_NAME} {S_NAME}\n
|
178 |
)
|
179 |
|
180 |
st.pydeck_chart(r)
|
181 |
|
182 |
# Create and display color scale legend
|
183 |
-
legend_img = create_colormap_legend(vmin, vmax, cmap, n_colors
|
184 |
|
185 |
# Create three columns, with the middle one being 30% width
|
186 |
left_spacer, center_col, right_spacer = st.columns([1, 1, 1])
|
|
|
48 |
colors = [cmap(i / (n_colors - 1)) for i in range(n_colors)]
|
49 |
return mcolors.ListedColormap(colors)
|
50 |
|
51 |
+
def create_colormap_legend(vmin, vmax, cmap, n_colors):
|
52 |
fig, ax = plt.subplots(figsize=(6, 0.8))
|
53 |
fig.subplots_adjust(bottom=0.5)
|
54 |
|
55 |
bounds = np.linspace(vmin, vmax, n_colors + 1)
|
56 |
norm = mcolors.BoundaryNorm(bounds, cmap.N)
|
57 |
cbar = fig.colorbar(plt.cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation='horizontal',
|
58 |
+
spacing='proportional', boundaries=bounds, format='%.0f')
|
59 |
cbar.set_ticks(bounds)
|
60 |
+
ax.set_title("緑被率 %", fontsize=10, pad=10)
|
61 |
|
62 |
buf = io.BytesIO()
|
63 |
plt.savefig(buf, format='png', dpi=300, bbox_inches='tight')
|
|
|
82 |
st.error("Failed to load data. Please try again later.")
|
83 |
return
|
84 |
|
85 |
+
# Convert FRAC_VEG to percentage
|
86 |
+
gdf['FRAC_VEG_PERCENT'] = gdf['FRAC_VEG'] * 100
|
87 |
+
|
88 |
# City filter
|
89 |
cities = sorted(gdf['CITY_NAME'].unique().tolist())
|
90 |
selected_cities = st.multiselect("市区町村", cities, default=[])
|
|
|
95 |
else:
|
96 |
gdf_filtered = gdf
|
97 |
|
98 |
+
selected_attribute = "FRAC_VEG_PERCENT"
|
|
|
99 |
|
100 |
# Custom CSS to create a box around the color scale controls
|
101 |
st.markdown("""
|
|
|
111 |
|
112 |
# Color scale controls in an expander
|
113 |
with st.expander("カラースケール設定", expanded=True):
|
114 |
+
st.markdown('<div class="color-scale-box">', unsafe_allow_html=True)
|
115 |
col1, col2, col3, col4 = st.columns(4)
|
116 |
with col1:
|
117 |
n_colors = st.slider("分割数", min_value=2, max_value=20, value=5)
|
118 |
with col2:
|
119 |
alpha = st.slider("透過率", min_value=0.0, max_value=1.0, value=0.8, step=0.1)
|
120 |
with col3:
|
121 |
+
vmin = st.number_input("最小値 (%)", value=0.0, step=1.0)
|
122 |
with col4:
|
123 |
+
vmax = st.number_input("最大値 (%)", value=100.0, step=1.0)
|
124 |
st.markdown('</div>', unsafe_allow_html=True)
|
125 |
|
126 |
# Other controls
|
|
|
176 |
layers=[layer],
|
177 |
initial_view_state=view_state,
|
178 |
map_style="mapbox://styles/mapbox/light-v9",
|
179 |
+
tooltip={"text": "{CITY_NAME} {S_NAME}\n緑被率: {FRAC_VEG_PERCENT:.2f}%"}
|
180 |
)
|
181 |
|
182 |
st.pydeck_chart(r)
|
183 |
|
184 |
# Create and display color scale legend
|
185 |
+
legend_img = create_colormap_legend(vmin, vmax, cmap, n_colors)
|
186 |
|
187 |
# Create three columns, with the middle one being 30% width
|
188 |
left_spacer, center_col, right_spacer = st.columns([1, 1, 1])
|