在 python 的 3D 图中移动刻度标签

Shift tick label in 3D plot in python

在我的图中,我的值属于轴上的哪个破折号并不是很明显,需要仔细查看。我希望它马上就清楚了。

现在我在红色中添加了它们所属的。当值稍微向上移动时,我认为它会更清楚。

这是我的代码

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x =  np.arange(1950,2010,1)
y = np.arange(0, 50,1)
X, Y = np.meshgrid(x, y)
zs = np.array([fun(y,x) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)

ax.plot_wireframe(X, Y, Z)

ax.view_init(25,-30)
plt.xlabel('Year')

plt.show()

谢谢

正确的解决方案是在 Axes3D 对象上使用 tick_params 函数,如下所示:

fig = plt.figure()
ax = Axes3D(fig)

ax.minorticks_on()
ax.tick_params(axis='both', width=10, labelsize=10, pad=0)

x =  np.arange(1950,2010,1)
y = np.arange(0, 50,1)
X, Y = np.meshgrid(x, y)
zs = np.array([fun(y,x) for x,y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)

ax.plot_wireframe(X, Y, Z)
ax.view_init(25,-30)
plt.xlabel('Year')

plt.show()

特别是tick_params函数有一个pad参数来控制距离。不幸的是,这似乎还没有完全实现:

Note

While this function is currently implemented, the core part of the Axes3D object may ignore some of these settings. Future releases will fix this. Priority will be given to those who file bugs.