如何为多个 geopandas 绘图层绘制多个图例?

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

我希望两个图例都显示两个图例,但它只显示一个图例。我该如何解决这个问题?

import geopandas
from shapely.geometry import Point
from shapely.geometry import Polygon
import matplotlib.pyplot as plt

coords_1 = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
coords_2 = ((1., 1.), (2., 1.), (2., 2.), (1., 2.), (1., 1.))

d = {'vsu': [10, 15], 'geometry': [Polygon(coords_1), Polygon(coords_2)]}
gdf = geopandas.GeoDataFrame(d)

p = {'gk': ["a", "b"], 'geometry': [Point(0.5, 0.5), Point(1.5, 1.5)]}
gdf_2 = geopandas.GeoDataFrame(p)

fig, ax = plt.subplots()

gdf.plot(column="vsu", scheme="EqualInterval", legend=True, ax=ax)
gdf_2.plot(column = "gk", ax=ax, legend=True)

plt.show()

python matplotlib legend geopandas
1个回答
0
投票
fig, ax = plt.subplots()

gdf.plot(column="vsu", scheme="EqualInterval", legend=True, ax=ax)
leg1 = ax.get_legend()

gdf_2.plot(column = "gk", ax=ax, legend=True)

ax.add_artist(leg1)

plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.