plotly / plotly/plotly.py

show geometries for both categorical and numerical fields in the same plot - px.choropleth

未关闭
#3,233 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

I am trying to create a US county map (including AK and HI in the bottom corner of the continental map) in plotly. I do not have numerical data for every county. In fact I only have data for 50 counties (approx). I want the map to contain the geometry for the for the counties with not data, so I can plot them in a different color. Otherwise the map is to empty. I tried with add.trace but I could not make it work.

``
import plotly.graph_objs as go
import plotly.express as px
import pandas as pd
from urllib.request import urlopen
import json

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

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})

df_nodata=df.loc[df.unemp <= 10]

df_nodata['categorical'] = 'no data'

df_data = df.loc[df.unemp > 10]

fig = px.choropleth(df_data,
geojson=counties,
locations=df_data.fips,
color=df_data.unemp,
scope='usa')

fig.add_trace(go.Figure(go.Choroplethmapbox(geojson=counties, locations=df_nodata.fips, z=df_nodata.categorical))
)

fig.show()

``
I am trying to combine the attached
Screenshot (80)
Screenshot (81)

layers.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先复现使用 px.choropleth 的示例以及尝试使用的 go.Choroplethmapbox trace,然后检查这些入口点如何组合地理图层。结果应在同一张美国地图上显示有数据的县和没有数据的县,并为没有数据的县使用一种不同的颜色。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。