Reputation: 469
In the plot below, how does one manipulate the z-axis label in such a way as to move it to the right?
Here is the code I'm using to create the plot:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.auto_scale_xyz([0, 100], [0, 30], [0, 1])
Z = fracStorCume[i,:,:]
surf = ax.plot_surface(X3d, Y3d, Z, cmap='autumn', cstride=2, rstride=2)
ax.set_xlabel('\n' + "Columns", linespacing=4)
ax.set_ylabel("Rows")
ax.set_zlabel("Fraction from \nstorage")
ax.set_zlim3d(0, 1) #ax.set_zlim(0, 1) #[neither of these options seem to do anything]
ax.set_yticks( np.arange(0,32,10))
ax.set_zticks(np.arange(0.05,1.01,0.25))
ax.pbaspect = [1., .33, 0.5]
ax.view_init(elev=40., azim=-65) #, azim=ii
ax.dist = 6
ax.yaxis.set_rotate_label(False)
ax.yaxis.label.set_rotation(0)
ax.zaxis.set_rotate_label(False)
ax.zaxis.label.set_rotation(0)
plt.subplots_adjust(left=0.05, right=0.80, top=.85, bottom=0.15)
plt.savefig(r'C:\tmp\3D_' + str(tstp) + '_TS_Stor.png')
Upvotes: 3
Views: 6580
Reputation: 4310
Apparently you are not the only one with this problem.
In new versions of matplotlib, this is how to do it:
ax.xaxis._axinfo['label']['space_factor'] = 2.8
See the explanation here: https://github.com/matplotlib/matplotlib/issues/3610
In older versions, you can use this crude workaround:
import matplotlib
matplotlib.use("TKAGG")
import matplotlib.pyplot as pyplot
import mpl_toolkits.mplot3d
figure = pyplot.figure(figsize=(8,4), facecolor='w')
ax = figure.gca(projection='3d')
xLabel = ax.set_xlabel('\nXXX xxxxxx xxxx x xx x', linespacing=3.2)
yLabel = ax.set_ylabel('\nYY (y) yyyyyy', linespacing=3.1)
zLabel = ax.set_zlabel('\nZ zzzz zzz (z)', linespacing=3.4)
plot = ax.plot([1,2,3],[1,2,3])
ax.dist = 10
pyplot.show()
Here's the stack thread where I got these from. The maintainer of mplot3d posted on there.
Upvotes: 1