在图例matplotlib中设置相同的比例

问题描述 投票:0回答:2

我正在处理地理空间数据,我有两个具有两个不同区域的 pandas 数据框,它们都有一个包含(多)多边形的列

geometry
和一个包含每个(多)多边形 I 的值的列
SCORE
想画图。

例如,这是西班牙各省(不包括加那利群岛)的绘图:

shapefile_prov.plot(column="SCORE", legend=True)
plt.xticks([])
plt.yticks([])

enter image description here

这是加那利岛数据框的图:

shapefile_prov_can.plot(column="SCORE", legend=True)
plt.xticks([])
plt.yticks([])

enter image description here

有没有办法使用与第一张图相同的颜色比例为加那利群岛的图着色?我的意思是,黄色应与大约高于 0.5 的

SCORE
值相关联,紫色应与大约低于 0.325 的值相关联。

python pandas matplotlib graphics geopandas
2个回答
0
投票

您可以使用

plt.clim(minValue, maxValue)
功能设置最小/最大颜色范围。 在两个图表上使用这些将使它们都具有相同的色阶,其中相同的颜色代表相同的值。

进一步阅读:


0
投票

一个快速/简单的选项将是

agg
分数的
min
/
max
并将其传递给
plot

cmap_range = (
    pd.concat([shapefile_prov["SCORE"], shapefile_prov_can["SCORE"]])
    .agg({"vmin": "min", "vmax": "max"})
)

shapefile_prov_can.plot(column="SCORE", legend=True, **cmap_range)

NB:下图使用

AxesDivider
来改善外观。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.