【问题标题】:Zoom an inline 3D matplotlib figure *without* using the mouse?*不*使用鼠标缩放内联 3D matplotlib 图形?
【发布时间】:2017-01-16 08:40:09
【问题描述】:

This question 解释了如何通过指定仰角和方位角来更改 matplotlib 中 3D 绘图的“相机位置”。 ax.view_init(elev=10,azim=20),例如。

有没有类似的方法来指定数字的缩放 - 即不使用鼠标?

我能找到的唯一相关问题是this one,但公认的答案涉及安装另一个库,然后还需要使用鼠标进行缩放。

编辑:

为了清楚起见,我不是在谈论更改图形大小(使用fig.set_size_inches() 或类似名称)。图形大小很好;问题是绘制的东西只占了图形的一小部分:

【问题讨论】:

    标签: python matplotlib plot 3d zooming


    【解决方案1】:

    最接近view_init 的解决方案是直接设置ax.dist。根据get_proj 的文档,“dist 是眼睛观察点到物点的距离”。 initial value is currently hardcodeddist = 10。较低的值(大于 0!)将导致绘图放大。

    注意:此行为并未真正记录在案,可能会发生变化。在大多数情况下,更改轴的限制以仅绘制相关部分可能是更好的解决方案。您可以使用ax.autoscale(tight=True) 方便地执行此操作。

    工作 IPython/Jupyter 示例:

    %matplotlib inline
    from IPython.display import display
    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    # Grab some test data.
    X, Y, Z = axes3d.get_test_data(0.05)
    
    # Plot a basic wireframe.
    ax.view_init(90, 0)
    ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
    plt.close()
    
    from ipywidgets import interact
    
    @interact(dist=(1, 20, 1))
    def update(dist=10):
        ax.dist = dist
        display(fig)
    

    输出

    dist = 10

    dist = 5

    【讨论】:

      猜你喜欢
      • 2013-11-07
      • 1970-01-01
      • 2011-01-02
      • 2015-04-20
      • 2023-03-06
      • 1970-01-01
      • 2011-05-10
      • 2016-08-17
      • 1970-01-01
      相关资源
      最近更新 更多