将matplotlib视图设置为Python中x-y平面的法线

将matplotlib视图设置为Python中x-y平面的法线,第1张

概述此代码发现 here是3d曲面图的示例: from mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import cmfrom matplotlib.ticker import LinearLocator, FormatStrFormatterimport matplotlib.pyplot as pltimport numpy as n 此代码发现 here是3d曲面图的示例:

from mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import cmfrom matplotlib.ticker import linearLocator,FormatStrFormatterimport matplotlib.pyplot as pltimport numpy as npfig = plt.figure()ax = fig.gca(projection='3d')X = np.arange(-5,5,0.25)Y = np.arange(-5,0.25)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.coolwarm,linewidth=0,antialiased=False)ax.set_zlim(-1.01,1.01)ax.zaxis.set_major_locator(linearLocator(10))ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))fig.colorbar(surf,shrink=0.5,aspect=5)plt.show()

和收益率

有没有办法设置绘图视图,使其与x-y轴完全垂直?这基本上将3-d曲线转换为2-d曲线,您可以使用颜色图来判断z变量的大小,而不是从z = 0基准位移.

解决方法 你想要的是ax.vIEw_init函数,其中elev = 90.见 this answer

编辑:

将ax.vIEw_init(azim = 0,elev = 90)添加到您的脚本后,我得到了这个:

总结

以上是内存溢出为你收集整理的将matplotlib视图设置为Python中x-y平面法线全部内容,希望文章能够帮你解决将matplotlib视图设置为Python中x-y平面的法线所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1194219.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存