show geometries for both categorical and numerical fields in the same plot - px.choropleth
還沒有人認領這個 Issue。
- 主要語言
- 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


layers.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先重現使用 px.choropleth 的範例以及嘗試使用的 go.Choroplethmapbox trace,然後檢查這些進入點如何組合地理圖層。結果應在同一張美國地圖上顯示有資料的郡和沒有資料的郡,並為沒有資料的郡使用一種不同的顏色。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- data-visualization
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100