plotly / plotly/plotly.py

Choropleth maps only render the first feature with a matching featureidkey, not all matching features

オープン
#4,660 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug P3
主要言語
Python
スター
18.8k
フォーク
2.8k
平均マージ
16時間 26分
マージ済み PR(30日)
21

説明

When px.choropleth() is called with a GeoJSON feature collection containing multiple features matching a single featureidkey value, only the first feature is rendered. I believe all features should be so rendered.

The following code generates two images: the first renders all four features, while the second renders only three. The first uses a featureidkey unique to all features, the second uses a featureidkey that is not unique -- only the first feature to match is rendered. :-(

#!/usr/bin/env python3

import pandas as pd
import plotly.express as px

# A simple GeoJSON with four features.  
# Each feature has a district.  
# One district has two features.
geojson = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "name": "Alpha",
                "district": "One",
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]]],
            },
        },
        {
            "type": "Feature",
            "properties": {
                "name": "Bravo",
                "district": "One",
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[5, 0], [5, 5], [10, 5], [10, 0], [5, 0]]],
            },
        },
        {
            "type": "Feature",
            "properties": {
                "name": "Charlie",
                "district": "Two",
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[0, 5], [0, 10], [5, 10], [5, 5], [0, 5]]],
            },
        },
        {
            "type": "Feature",
            "properties": {
                "name": "Delta",
                "district": "Three",
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[5, 5], [5, 10], [10, 10], [10, 5], [5, 5]]],
            },
        },
    ],
}

districts = {
    f["properties"]["name"]: f["properties"]["district"] for f in geojson["features"]
}

# A simple dataframe relating names and districts from the above GeoJSON data.
# i.e., [{'name': 'Alpha', 'district': 'One'}, ...]
data = [f['properties'] for f in geojson['features']]

df = pd.DataFrame(data)

# This code generates two maps from the data:
# * The name map shows all four squares in the same color (count = 1)
# * The district map shows _three_ squares, one with one color (count = 2) and two with another color (count = 1)

# What I expected:
# * The district map should show all four squares, two with light color and two with dark
for key in ["name", "district"]:

    region_counts = df.groupby([key], observed=False).size().reset_index(name="count")

    fig = px.choropleth(
        region_counts,
        geojson=geojson,
        fitbounds='geojson',
        locations=key,
        color="count",
        featureidkey=f"properties.{key}",
    )

    fig.write_image(f"mwe-{key}.png")

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供されたスクリプトから px.choropleth() の2つの呼び出しを再現し、locations と featureidkey を通じて一意な名前と繰り返される地区の値を比較します。choropleth のエントリーポイントと GeoJSON feature のマッチングを追跡し、一意な名前の結果を維持したまま地区マップに4つすべてのポリゴンをレンダリングして、完了を確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。