我試圖將 clabels 的文本置于直立位置。在 matplotlib 3.2.1 中,可以將旋轉設定為零。如何在以下答案中找到它:更改輪廓 clabel 文本物件的方向 但是在更新到 matplotlib 3.4.3 后,我通過執行此操作獲得了 cls 的 NoneType 錯誤。
im = plt.pcolormesh(lon, lat, values, cmap=colormap, vmax=40, vmin=-40, transform=ccrs.PlateCarree())
lvls = np.arange(-40, 40, 5)
ctr = plt.contour(lon, lat, values, levels=lvls, colors='#242424', linewidths=0.1, transform=ccrs.PlateCarree())
cls = plt.clabel(ctr, inline=True, fontsize=5, fmt="%d", colors='#242424', rightside_up=True, use_clabeltext=True)
for label in cls:
label.set_rotation(0)
有沒有另一種方法可以將文本置于直立位置?
問候
uj5u.com熱心網友回復:
好的。我已經找到了解決我的問題的方法。我必須通過以下方式訪問文本標簽:
for label in cls:
label.set_rotation(0)
但是通過:
for label in ctr.labelTexts:
label.set_rotation(0)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/339918.html
標籤:Python matplotlib
