首页 > 解决方案 > Plotly Choropleth 不使用 ISO 代码显示颜色

问题描述

我希望在美国绘制计数(频率)和区域(使用区域 ISO 代码)的等值线。我目前正在使用情节,但我似乎无法弄清楚为什么不显示应该显示频率的颜色。我没有 fibs 专栏,我只有 ISO。

谢谢..

from urllib.request import urlopen
import pandas as pd
import plotly.express as px
import json
from pyspark.sql.types import IntegerType



# with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as # response:
#     counties = json.load(response)

df = location_test.toPandas()

fig = px.choropleth_mapbox(df, locations=df['location_region_iso_code'], color=df['count'],
                           color_continuous_scale="Viridis",
                           range_color=(0, 15),
                           mapbox_style="carto-positron",
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           opacity=0.5,
                           labels={'count':'Count'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

这是我得到的输出:显示区域和频率的地图

标签: pythonplotlyisochoropleth

解决方案


推荐阅读