一次设置所有 matplotlib 轴标签

Setting all matplotlib axis labels at once

因为我通常尝试在 matplotlib 图中标记我的轴,我发现我经常单独标记 x/y/z 轴,使用这样的东西:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
# <plot plot plot>
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')     

有没有办法将单个轴标签设置减少到一个命令,理想情况下类似于 ax.set_labels(['x', 'y', 'z'])

您可以使用 ax.update 接近。例如:

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

ax.update({'xlabel':'x', 'ylabel':'y', 'zlabel':'z'})

来自 docs for ax.update:

update(props)

Update the properties of this Artist from the dictionary prop.

因此,您不仅可以使用 ax.update 更新坐标轴标签,还可以帮助减少其他地方的代码。只需将 属性 传递给字典中的更新即可。可以使用 ax.properties()

找到可用属性列表