我的Choropleth贴图卡住了并且无法完成?

时间:2020-03-05 02:30:19

标签: python plotly choropleth

在这里相对较新,在一般情况下是Python的新功能,但是尝试与Plotly Express一起创建自己的Choropleth地图,使我可以对国家/地区的自定义数据进行颜色编码。但是,我在实际加载地图时遇到了麻烦。我已经可以不使用任何数据来加载本地Choropleth映射,但是当我将自己的geojson数据集链接到该函数时,它就陷入了第30行的加载。我还不能弄清楚为什么,因为它只是卡住了,没有其他问题可解决。

非常感谢您的帮助!

import random
from token_file import token
import pandas as pd
import plotly.express as px
import json


with open('documents/countries.geojson') as f:
    data = json.load(f)

countries = {}

for features in data["features"]:
    if features["properties"]["ISO_A3"] != "-99":
        name = features["properties"]["ADMIN"]
        iso = features["properties"]["ISO_A3"]
        geo = features["geometry"]
        val = random.randint(0, 100)
        values = pd.Series([name, iso, val], index=["Name", "ISO", "Val"])
        countries[name] = values
    else:
        continue

countries = pd.DataFrame(countries)
countries = countries.transpose()

print(countries)

px.set_mapbox_access_token(token)
map = px.choropleth_mapbox(countries, locations="ISO", zoom=1, hover_name="Name", hover_data=["ISO"],
                           color="Val", color_continuous_scale="Viridis", mapbox_style="carto-positron")
map.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
map.show()

0 个答案:

没有答案