向右(或向左)移动 3D 图 z 轴标签

Move 3D plot z-axis label right (or left)

在下图中,如何操纵 z 轴标签使其向右移动?

这是我用来创建情节的代码:

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:\tmpD_' + str(tstp) + '_TS_Stor.png')

显然您不是唯一遇到此问题的人。

在新版本的 matplotlib 中,这是如何做到的:

ax.xaxis._axinfo['label']['space_factor'] = 2.8

查看这里的解释:https://github.com/matplotlib/matplotlib/issues/3610

在旧版本中,您可以使用这种粗略的解决方法:

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 我从中获取这些的堆栈线程。 mplot3d 的维护者在那里发帖。