Reputation: 101
I've encountered a really strange problem using matploblib's 3D plot, where if I make a z-axis label more than 4 characters long it will reverse the orientation of the label. I've tried playing about with the label padding and the fontsize but can't seem to find the reason why it's doing this. The following code will make a z-label the right way up:
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax.patch.set_facecolor('black')
plt.setp([ax.get_xticklines(), ax.get_yticklines(), ax.get_xticklabels(), ax.get_yticklabels(),
ax.get_zticklabels(),ax.spines.values(), ax.set_xlabel('east',fontsize=14,labelpad=8),
ax.set_ylabel('north',fontsize=14, labelpad=5),ax.set_zlabel('al m', labelpad =0)],
color='#03fc14')
axes = fig.gca(projection='3d')
zLabel = axes.set_zlabel('al m',fontsize=14, color='#03fc14',rotation='vertical', labelpad =-5 )
ax.scatter(ku.east, ku.north, ku.alt, color = 'blue', alpha = 0.3,label = 'ku')
ax.scatter(*list(zip(*atm.coords[slice(0,len(atm.coords),50)])), atm.alt[slice(0,len(atm.coords),50)],
color = 'orange', alpha=0.3, label = 'atm')
plt.legend(loc='best')
ax.view_init(26, 40)
fig.tight_layout()
whereas this code (changing nothing else except the z-label) reverses the direction of the z-label:
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ax.patch.set_facecolor('black')
plt.setp([ax.get_xticklines(), ax.get_yticklines(), ax.get_xticklabels(), ax.get_yticklabels(),
ax.get_zticklabels(),ax.spines.values(), ax.set_xlabel('east',fontsize=14,labelpad=8),
ax.set_ylabel('north',fontsize=14, labelpad=5),ax.set_zlabel('alt m', labelpad =0)],
color='#03fc14')
axes = fig.gca(projection='3d')
zLabel = axes.set_zlabel('alt /m',fontsize=14, color='#03fc14',rotation='vertical', labelpad =-5 )
ax.scatter(ku.east, ku.north, ku.alt, color = 'blue', alpha = 0.3,label = 'ku')
ax.scatter(*list(zip(*atm.coords[slice(0,len(atm.coords),50)])), atm.alt[slice(0,len(atm.coords),50)],
color = 'orange', alpha=0.3, label = 'atm')
plt.legend(loc='best')
ax.view_init(26, 40)
fig.tight_layout()
Here are links to images of the plots:
Using 'al m' as the z-axis label
Using 'alt m' as the z-axis label
I am using matplotlib version 3.1.1 and python version 3.7.4.
Any explanation or advice would be greatly appreciated.
Upvotes: 2
Views: 445
Reputation: 101
I managed to overcome the problem with the following:
axes = fig.gca(projection='3d')
ax.zaxis.set_rotate_label(False) # disable automatic rotation (so that I can actually subsequently change it)
zLabel = axes.set_zlabel('alt /m',fontsize=14, color='#03fc14',rotation=90, labelpad =0 )
Upvotes: 2