Choropleth maps only render the first feature with a matching featureidkey, not all matching features
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 18.8k
- Fork
- 2.8k
- Merge trung bình
- 16 giờ 26 phút
- Pull request đã merge (30 ngày)
- 21
Mô tả
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")
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện hai lệnh gọi px.choropleth() từ script được cung cấp, so sánh tên duy nhất và các giá trị quận lặp lại thông qua locations và featureidkey. Theo dõi điểm vào của choropleth và việc đối sánh các feature GeoJSON, sau đó xác minh việc hoàn tất bằng cách render cả bốn polygon trong bản đồ quận, đồng thời giữ nguyên kết quả của tên duy nhất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 28/100