Geopandas plot 为每个数据点而不是颜色条制作标签
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。它不是制作颜色条,而是为该列中的每一行制作标签。感谢任何帮助。
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,
)
这是我的简单代码:
gdf_MA_outage.plot(column = 'total_customers_affected_by_city' , cmap = 'OrRd' , figsize = (16,16) , legend = True)
'total_customers_affected_by_city' 范围从 1 到 200000。它不是制作颜色条,而是为该列中的每一行制作标签。感谢任何帮助。
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,
)