簡體   English   中英

Geopandas plot 為每個數據點而不是顏色條生成 label

[英]Geopandas plot makes label for every datapoint instead of a colorbar

這是我的簡單代碼:

gdf_MA_outage.plot(column = 'total_customers_affected_by_city' , cmap = 'OrRd' , figsize = (16,16) , legend = True)

'total_customers_affected_by_city' 的范圍從 1 到 200000。它不是制作顏色條,而是為該列中的每一行制作 label。 任何幫助表示贊賞。

我還不能發布圖片,所以我只能發布圖片的鏈接

total_customers_affected_by_city必須是字符串,因此它被視為分類。 將其更改為數字列,您將獲得一個顏色條。 下面的代碼顯示了您在我故意將列設置為字符串而不是數字的地方所描述的內容。

import geopandas as gpd
import numpy as np

gdf_MA_outage = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres")).loc[
    lambda d: (d["continent"] == "Europe") & (~d["iso_a3"].isin(["-99", "RUS"]))
]

gdf_MA_outage["total_customers_affected_by_city"] = np.random.randint(1, 200000, len(gdf_MA_outage)).astype(str)

gdf_MA_outage.plot(
    column="total_customers_affected_by_city",
    cmap="OrRd",
    figsize=(16, 16),
    legend=True,
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM