在后台绘制具有不同形状文件的多个子图

发布于 2025-01-17 05:53:07 字数 861 浏览 5 评论 0原文

我正在尝试使用 matplotlib 并排绘制 GeoPandas shapefile,但标题、xlabel 和 ylabel 未正确绘制。

fig, axes = plt.subplots(1,2, figsize=(10,3), sharex=True, sharey=True)

base = subs.boundary.plot(color='black', linewidth=0.1, ax=axes[0])
cluster.plot(ax=base, column='pixel', markersize=20, legend=True, zorder=2)
plt.title('THHZ')
plt.xlabel('Longitude')
plt.ylabel('Latitude')


base = forest.boundary.plot(color='black', linewidth=0.2, ax=axes[1])
cluster.plot(ax=base, column='forest', markersize=20, legend=True, zorder=2)
plt.title('Forest')

这就是我得到的

在此处输入图像描述

这就是我想要的

在此处输入图像描述

I am trying to plot side by side GeoPandas shapefiles using matplotlib but the titles, xlabel and ylabel are not plotting correctly.

fig, axes = plt.subplots(1,2, figsize=(10,3), sharex=True, sharey=True)

base = subs.boundary.plot(color='black', linewidth=0.1, ax=axes[0])
cluster.plot(ax=base, column='pixel', markersize=20, legend=True, zorder=2)
plt.title('THHZ')
plt.xlabel('Longitude')
plt.ylabel('Latitude')


base = forest.boundary.plot(color='black', linewidth=0.2, ax=axes[1])
cluster.plot(ax=base, column='forest', markersize=20, legend=True, zorder=2)
plt.title('Forest')

This is what I get

enter image description here

This is what I want

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脸赞 2025-01-24 05:53:07

您混合了面向对象和 pyplot 风格的 matplotlib 交互。 plt.* 调用遵循当前轴的逻辑进行操作。更多详细信息请参见此处的 matplotlib 文档: Pyplot 与面向对象的接口。我不知道您的绘图函数调用的行为如何(代码未包含在您的帖子中)。

要确定您正在与哪些轴进行交互,请使用您已有的axes对象进行面向对象的调用:

axes[0].set_title('THHZ')
axes[0].set_xlabel('Longitude')
axes[0].set_ylabel('Latitude')
axes[1].set_title('Forest')

您还可以在紧凑的图形布局的最后。

You have a mixture of object-oriented and pyplot-style matplotlib interactions. The plt.* calls are following a logic of the current axis to act upon. More detail from the matplotlib docs here: Pyplot vs Object Oriented Interface. I don't know how that behaves with your plotting function calls (code not included in your post).

To be certain of what axes you are interacting with, use the object-oriented calls using the axes object you already have:

axes[0].set_title('THHZ')
axes[0].set_xlabel('Longitude')
axes[0].set_ylabel('Latitude')
axes[1].set_title('Forest')

You can also add fig.tight_layout() at the very end for a compacted figure layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文