kunifujiwara commited on
Commit
8f75bb5
β€’
1 Parent(s): 28e9e9a

modify pages

Browse files
pages/2_🌲_Japan_Vegetation_Cover.py CHANGED
@@ -8,6 +8,7 @@ import os
8
  import requests
9
  import json
10
  from shapely.geometry import shape
 
11
 
12
  st.set_page_config(layout="wide")
13
 
@@ -113,7 +114,12 @@ def app():
113
  else:
114
  elev_scale = 1
115
 
116
- color_scale = cm.LinearColormap(colors=palette, vmin=gdf[selected_attribute].min(), vmax=gdf[selected_attribute].max(), n=n_colors)
 
 
 
 
 
117
  gdf['color'] = gdf[selected_attribute].apply(lambda x: color_scale(x))
118
  gdf['color'] = gdf['color'].apply(lambda x: [int(x[1:3], 16), int(x[3:5], 16), int(x[5:7], 16)])
119
 
 
8
  import requests
9
  import json
10
  from shapely.geometry import shape
11
+ import matplotlib.pyplot as plt
12
 
13
  st.set_page_config(layout="wide")
14
 
 
114
  else:
115
  elev_scale = 1
116
 
117
+ # Create a list of colors based on the selected palette and number of colors
118
+ cmap = plt.get_cmap(palette)
119
+ colors = [cmap(i / (n_colors - 1)) for i in range(n_colors)]
120
+ hex_colors = ['#%02x%02x%02x' % (int(r * 255), int(g * 255), int(b * 255)) for r, g, b, _ in colors]
121
+
122
+ color_scale = cm.LinearColormap(colors=hex_colors, vmin=gdf[selected_attribute].min(), vmax=gdf[selected_attribute].max())
123
  gdf['color'] = gdf[selected_attribute].apply(lambda x: color_scale(x))
124
  gdf['color'] = gdf['color'].apply(lambda x: [int(x[1:3], 16), int(x[3:5], 16), int(x[5:7], 16)])
125