在后台绘制具有不同形状文件的多个子图
我正在尝试使用 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
This is what I want
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您混合了面向对象和 pyplot 风格的
matplotlib
交互。plt.
* 调用遵循当前轴的逻辑进行操作。更多详细信息请参见此处的matplotlib
文档: Pyplot 与面向对象的接口。我不知道您的绘图函数调用的行为如何(代码未包含在您的帖子中)。要确定您正在与哪些轴进行交互,请使用您已有的axes对象进行面向对象的调用:
您还可以在紧凑的图形布局的最后。
You have a mixture of object-oriented and pyplot-style
matplotlib
interactions. Theplt.
* calls are following a logic of the current axis to act upon. More detail from thematplotlib
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:You can also add
fig.tight_layout()
at the very end for a compacted figure layout.