這是我的簡單代碼:
gdf_MA_outage.plot(column = 'total_customers_affected_by_city' , cmap = 'OrRd' , figsize = (16,16) , legend = True)
“total_customers_affected_by_city”的范圍從 1 到 200000。它不是制作顏色條,而是為該列中的每一行制作標簽。任何幫助表示贊賞。

uj5u.com熱心網友回復:
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,
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/440746.html
標籤:Python matplotlib 大熊猫 彩条
