我需要在3D matplotlib上绘制一个f(z)函数,但是在一个局部x轴上,由两个点定义并在它们之间填充,以保持如图所示:
我有这两个点来定义局部轴x,它们之间的20个值和f(z)对应的20个值,但是我不知道如何绘制。有人能帮我吗?你知道吗
valuesx = np.arange(0.0, 5, 5/20) # local axis values x
self.listax.append(valuesx)
for l in valuesx:
fy= 2*x**2-4 #equation
fyx = eval(fy, {'x': l})
self.listay.append(fyx)
x = [self.listax]
y = [self.listay]
z = [1, 5]
verts = [list(zip(x, y, z))]
self.axes.add_collection3d(Poly3DCollection(verts, facecolor = 'red', alpha=0.6), zs='z')
self.fig.canvas.draw()
抱歉,这是一个有点快速和肮脏的答案,但下面的例子应该可以帮助您:
https://matplotlib.org/gallery/mplot3d/polys3d.html
根据您的示例调整上述内容:
应该给你:
然后,可以根据需要调整限制,并调整zs变量以沿x轴上的值绘制。你知道吗
相关问题 更多 >
编程相关推荐