美文网首页
Python画 3d 图

Python画 3d 图

作者: 火卫控 | 来源:发表于2023-04-24 23:28 被阅读0次

    Python画 3d 图

    3D

    代码如下

    import numpy as np
    from matplotlib import cm
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d.axes3d import get_test_data
    
    
    fig = plt.figure(figsize=plt.figaspect(0.5))
    
    ax = fig.add_subplot(1,2,1,projection='3d')
    
    X = np.arange(-5,5,0.1)
    Y = np.arange(-5,5,0.1)
    X,Y=np.meshgrid(X,Y)
    
    
    R = np.sqrt(X**2 + Y**2)
    
    Z = np.sin(R)
    
    surf = ax.plot_surface(X,Y,Z,rstride=1,cstride=1,
                           cmap=cm.GnBu,linewidth=0,antialiased=False)
    ax.set_zlim3d(-1.01,1.01)
    
    fig.colorbar(surf,shrink=0.5,aspect=10)
    
    ax = fig.add_subplot(1,2,2,projection='3d')
    X,Y,Z = get_test_data(0.05)
    ax.plot_wireframe(X,Y,Z,rstride=10,cstride=10)
    
    outfile = '3dGraph.png'
    plt.savefig(outfile,dpi=300)
    print('Image saved to {0}'.format(outfile))
    plt.show()
    

    相关文章

      网友评论

          本文标题:Python画 3d 图

          本文链接:https://www.haomeiwen.com/subject/vxepjdtx.html