Choropleth贴图未在输出中显示颜色变化 [英] Choropleth map is not showing color variation in the output

查看:160
本文介绍了Choropleth贴图未在输出中显示颜色变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使将Choropleth与 geo_data 关联并且将 data frame 中的data参数关联之后,输出映射中也没有任何颜色变化> choropleth 方法.

I am not getting any color variation in my output map even after the choropleth is linked with the geo_data and the data frame is linked with data parameter in the choropleth method.

我正确地提供了"key_on" 参数,并正确地提供了"columns" 参数.我已经从数据框中删除了所有NULL值.

I have provided the "key_on" parameter rightly and the "columns" parameter rightly. I have removed all the NULL values from the Dataframe.

import pandas as pd
from pandas import read_csv
import folium
import os
import webbrowser

crimes = read_csv('Dataframe.csv',error_bad_lines=False)

vis = os.path.join('Community_Areas.geojson')
m = folium.Map(location = [41.878113, -87.629799], zoom_start = 10, tiles = "cartodbpositron")
m.choropleth(geo_data=vis, data = crimes, columns = ['Community Area', 'count'], fill_color = 'YlGn', key_on = 'feature.properties.area_numbe')
folium.LayerControl().add_to(m)
m.save('map.html')
webbrowser.open(filepath)

我期望彩色的鹅卵石图,但是实际输出是完全灰色的.我将在下面的链接中添加代码,数据和输出.

I expected a colored choropleth map, but the actual output was completely grey. I will add the code, data, output in the link below.

代码链接: https://github.com/rahul0070/Stackoverflow_question_data

推荐答案

读取数据后,我发现您没有将Community Area列的数据类型转换为字符串类型,因为geojson文件包含以下形式的密钥:细绳.因此,键和列的数据类型都应该匹配.

After reading the data what I found was you did not convert the data type of Community Area column to string type as the geojson file contains the key in the form of string. So the data type of both the key and column should match.

这是您答案的完整解决方案

Here is a full fledged solution to your answer

# importing libraries
import pandas as pd
from pandas import read_csv
import folium
import os
import webbrowser
# read the data
crimes = read_csv('Dataframe.csv',error_bad_lines=False)
# convert float to int then to string
crimes['Community Area'] = crimes['Community Area'].astype('int').astype('str')
# choropleth map
vis = 'Community_Areas.geojson'
m = folium.Map(location = [41.878113, -87.629799], zoom_start = 10, tiles = "cartodbpositron")
m.choropleth(geo_data=vis, data = crimes, columns = ['Community Area', 'count'], fill_color = 'YlGn', key_on = 'feature.properties.area_num_1')
folium.LayerControl().add_to(m)
m.save('map.html')
webbrowser.open('map.html')

如果您难以理解代码的任何部分,请发表评论.对于key_on参数,您也可以尝试feature.properties.area_numbe

Please comment if you find difficulty in understanding any part of code. For the key_on parameter you can also try feature.properties.area_numbe

这篇关于Choropleth贴图未在输出中显示颜色变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆