【问题标题】:Move 3D plot z-axis label right (or left)向右(或向左)移动 3D 绘图 z 轴标签
【发布时间】:2015-08-05 00:13:38
【问题描述】:

在下图中,如何操作 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')

【问题讨论】:

    标签: python mplot3d


    【解决方案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 的维护者在那里发帖。

    【讨论】:

    • 很遗憾您的建议没有奏效。我尝试将建议的命令放在脚本中的几个不同位置(即,在ax.set_zlabel 之后或ax.zaxis.label.set_rotation(0) 之后并在ax.zaxis.set_rotate_label(False) 之前尝试过。我还尝试将填充量增加到 200,但一切都没有响应。
    • 您是否尝试使用该链接第二个答案中的 ax.zaxis.set_label_coords?
    • 我确实尝试过ax.zaxis.set_label_coords,但和以前一样完全没有反应。我注释掉了ax.zaxis.set_rotate_label(False)ax.zaxis.label.set_rotation(0),以防出现某种冲突,但这只会导致标签轮换。可能与我设置的其他参数有冲突吗?
    • 查看我的新编辑。我很确定其中一个应该可以工作。
    • 选项 1,即ax.xaxis._axinfo['label']['space_factor'] = 2.8 效果很好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    相关资源
    最近更新 更多