【问题标题】:Gridlines Above 3D Scatter Plot in matplotlibmatplotlib 中 3D 散点图上方的网格线
【发布时间】:2017-01-17 01:08:47
【问题描述】:

使用 matplotlib 制作 3D 散点图时,我似乎无法控制轴是在图上方还是下方。例如,如果 ax1.elev ,以下代码将始终在绘图上方具有 x 和 y 轴

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d

fig = plt.figure('Test')
X = np.random.rand(1,100)
Y = np.random.rand(1,100)
Z = np.random.rand(1,100)

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

ax1.scatter(X,Y,Z)
ax1.view_init(-10,45)

是否可以强制 x 和 y 轴以及网格线和平面位于绘图下方,即使 ax1.elev

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我以this question 的代码为例(感谢crayzeewulf)。除了 z 轴,我们对 x 和 y 轴都这样做

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import axes3d
    
    fig = plt.figure('Test')
    X = np.random.rand(1,100)
    Y = np.random.rand(1,100)*10
    Z = np.random.rand(1,100)
    
    ax1 = fig.add_subplot(111, projection = '3d')
    
    ax1.scatter(X,Y,Z)
    ax1.view_init(-10,45)
    
    tmp_planes = ax1.zaxis._PLANES 
    ax1.xaxis._PLANES = ( tmp_planes[3], tmp_planes[2], 
                         tmp_planes[1], tmp_planes[0], 
                         tmp_planes[5], tmp_planes[4])
    
    ax1.yaxis._PLANES = ( tmp_planes[3], tmp_planes[2], 
                         tmp_planes[1], tmp_planes[0], 
                         tmp_planes[5], tmp_planes[4])
    
    view_1 = (25, -135)
    view_2 = (-10, 45)
    init_view = view_2
    ax1.view_init(*init_view)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 2012-07-07
      • 1970-01-01
      相关资源
      最近更新 更多