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

时间:2015-08-03 23:42:43

标签: python mplot3d

在下图中,如何操纵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:\tmp\3D_' + str(tstp) + '_TS_Stor.png')

enter image description here

1 个答案:

答案 0 :(得分:1)

显然你并不是唯一有这个问题的人。

在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的维护者发布在那里。