z 标签没有出现在我的图中。怎么了?
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
plt.show()
ax.set_zlabel("z")
和 ax.set(zlabel="z")
都不起作用。 x 和 y 标签工作正常。
最佳答案
这是一个填充问题。
labelpadfloat The distance between the axis label and the tick labels. Defaults to
rcParams["axes.labelpad"]
(default: 4.0) = 4.
您可以使用matplotlib.axis.ZAxis.labelpad
调整 z 轴的值:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("StackOverflow", rotation=90)
ax.zaxis.labelpad=-0.7 # <- change the value here
plt.show();
输出:
关于python - Z 标签未显示在 3d matplotlib 散点图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75275130/