加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 12:09:15 所属栏目:Python 来源:网络整理
导读:此代码发现 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
此代码发现 here是3d曲面图的示例:

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator,FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np

fig = 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()

和收益率

enter image description here

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

解决方法

你想要的是ax.view_init函数,其中elev = 90.见 this answer

编辑:

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

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读