Home > Software design >  How to change text orientation of pyplot clabel to upright?
How to change text orientation of pyplot clabel to upright?

Time:10-29

I tried to bring the text of clabels to an upright position. In matplotlib 3.2.1 it was possible to set the rotation to zero. How you can find it in following answer: change orientation of contour clabel text objects But after updating to matplotlib 3.4.3 i've got an NoneType Error for cls by doing this.

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)

Is there another way to bring the text to an upright position?

regards

CodePudding user response:

Ok. I've found a solution for my issue. I have to access the textlabels not by:

for label in cls:
    label.set_rotation(0)

But by:

for label in ctr.labelTexts:
    label.set_rotation(0)
  • Related