我正在嘗試使用 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')
這就是我得到的

這就是我要的

uj5u.com熱心網友回復:
您混合了面向物件和 pyplot 樣式的matplotlib互動。plt.* 呼叫遵循當前軸的邏輯以進行操作。更多詳細資訊來自matplotlib此處的檔案:Pyplot vs Object Oriented Interface。我不知道您的繪圖函式呼叫的行為如何(代碼未包含在您的帖子中)。
axes要確定您正在與哪些軸進行互動,請使用您已有的物件使用面向物件的呼叫:
axes[0].set_title('THHZ')
axes[0].set_xlabel('Longitude')
axes[0].set_ylabel('Latitude')
axes[1].set_title('Forest')
您還可以fig.tight_layout()在最后添加緊湊的圖形布局。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/451517.html
標籤:Python matplotlib 阴谋 大熊猫
