简体   繁体   English

matplotlib 3d:轴 label 更改脊椎位置时的填充

[英]matplotlib 3d: Axis label padding when spine positions are changed

In the code below, the y-axis label is not in the place I want it.在下面的代码中,y 轴 label 不在我想要的位置。

I've seen posts about how to adjust the axis label padding and how to move the axis spines, but not the two together.我看过有关如何调整轴 label 填充以及如何移动轴刺的帖子,但不是将两者一起移动。 Below, I change the position of the z and y splines and adjust the padding on the x and y axis labels without any issue.下面,我更改 z 和 y 样条的 position 并调整 x 和 y 轴标签上的填充没有任何问题。 The y-label, however, lands exactly on the spine.然而,y 标签正好落在书脊上。 Adjusting the padding does not move the label further from the spine, but rather up and down the spine.调整填充不会使 label 远离脊椎,而是向上和向下移动脊椎。 Am I missing something in my code?我的代码中是否缺少某些内容? Any help appreciated.任何帮助表示赞赏。

from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure(1)
plt.clf()
plt.ion()

ax1 = fig.add_subplot(111, projection='3d')

ax1.yaxis._axinfo['juggled'] = (1,1,1)
ax1.zaxis._axinfo['juggled'] = (1,2,0)

ax1.set_xlabel("X label", labelpad=-10)
ax1.set_ylabel("Y label", labelpad=-20)
ax1.set_zlabel("Z label", labelpad= -8)


ax1.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax1.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax1.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax1.grid(False)


for line in ax1.xaxis.get_ticklines():
    line.set_visible(False)
for line in ax1.yaxis.get_ticklines():
    line.set_visible(False)
for line in ax1.zaxis.get_ticklines():
    line.set_visible(False)
    
ax1.xaxis.set_ticklabels([])
ax1.yaxis.set_ticklabels([])
ax1.zaxis.set_ticklabels([])

在此处输入图像描述

Your label doesn't land on the spine.您的 label 不会落在脊椎上。 It's just the angle that makes it look like that.只是角度使它看起来像那样。 You can try to move your plot and you'll see that by yourself.您可以尝试移动您的 plot,您会自己看到。

The labelpad parameters makes it move further in X and Z , that's why from this perspective it seems to move only down and up the Y spine. labelpad参数使它在XZ中移动得更远,这就是为什么从这个角度来看它似乎只在Y脊椎上上下移动。

I modified the labelpad to show you from another perspective.我修改了 labelpad 以从另一个角度向您展示。

fig = plt.figure(1)
plt.clf()
plt.ion()

ax1 = fig.add_subplot(111, projection='3d')

ax1.yaxis._axinfo['juggled'] = (1, 1, 1)
ax1.zaxis._axinfo['juggled'] = (1, 2, 0)

ax1.set_xlabel("X label", labelpad=10)
ax1.set_ylabel("Y label", labelpad=10)
ax1.set_zlabel("Z label", labelpad=10)

ax1.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax1.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax1.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax1.grid(False)

for line in ax1.xaxis.get_ticklines():
    line.set_visible(False)
for line in ax1.yaxis.get_ticklines():
    line.set_visible(False)
for line in ax1.zaxis.get_ticklines():
    line.set_visible(False)

ax1.xaxis.set_ticklabels([])
ax1.yaxis.set_ticklabels([])
ax1.zaxis.set_ticklabels([])

And this is the figure这就是数字

另一种观点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM