python - 为什么在 Folium.choropleth 中使用 bins 参数时会发生 KeyError?
问题描述
我正在研究 Folium choropleth。
当我在bins
参数上输入 11 个值时,KeyError
会发生。
当我输入低于 10 个值时,不会发生错误。
我的代码如下:
map.choropleth(geo_data = json.load,
data = dataframe,
columns=[column_names],
fill_color = 'YlGnBu',
key_on = 'features.id',
bins = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50])
错误如下:
KeyError Traceback (most recent call last)
<ipython-input-13-2a6160fee268> in <module>
4 fill_color = 'YlGnBu',
5 key_on = 'properties.name',
----> 6 bins = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50])
7
8
~\anaconda3\lib\site-packages\folium\folium.py in choropleth(self, *args, **kwargs)
416 )
417 from folium.features import Choropleth
--> 418 self.add_child(Choropleth(*args, **kwargs))
419
420 def keep_in_front(self, *args):
~\anaconda3\lib\site-packages\folium\features.py in __init__(self, geo_data, data, columns, key_on, bins, fill_color, nan_fill_color, fill_opacity, nan_fill_opacity, line_color, line_weight, line_opacity, name, legend_name, overlay, control, show, topojson, smooth_factor, highlight, **kwargs)
1181 # We add the colorscale
1182 nb_bins = len(bin_edges) - 1
-> 1183 color_range = color_brewer(fill_color, n=nb_bins)
1184 self.color_scale = StepColormap(
1185 color_range,
~\anaconda3\lib\site-packages\branca\utilities.py in color_brewer(color_code, n)
150 if not explicit_scheme:
151 # Check to make sure that it is not a qualitative scheme.
--> 152 if scheme_info[base_code] == 'Qualitative':
153 matching_quals = []
154 for key in schemes:
KeyError: 'YlGnBu'
为了找出原因,我用谷歌搜索并找到了下面的问题。
在 Choropleth #1254 中使用“bins”参数后出现 KeyError
有评论说KeyError
出现的原因是因为' color YlGn has 9 shades '。
真的吗?我在哪里可以查看颜色的阴影信息?
解决方案
推荐阅读
- oracle - ora-00907 子查询中缺少右括号
- php - 如果值是变量而不是字符串,为什么 PHP in_array() 返回 false?
- spring - 在spring boot h2中按一个元素在arraylist中查询
- r - 谷歌应用引擎灵活与 docker '站点无法访问'
- node.js - 用户玩游戏时的事件处理程序
- angular - Angular - 为 nbgDropDown 设置默认值
- c# - 提取电话号码并排除无关字符
- c# - 如何围绕wpf中的固定点旋转3D形状?
- php - Lumen 中 '$app->run()' 的实现在哪里?
- mysql - Codeigniter 3 - Highcharts mysql json 示例