Matplotlib:如何在3D图形中绘制垂直平面 [英] Matplotlib: how to draw a vertical plane in 3D figure

查看:100
本文介绍了Matplotlib:如何在3D图形中绘制垂直平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个由

定义的垂直平面

5 = x + y

在 3D 图形中,使用 Matplotlib.

我看了

I want to draw a vertical plane defined by

5 = x + y

in a 3D figure, using Matplotlib.

I had a look at this and this, but no chance. I also found mpl_toolkits.mplot3d.art3d.line_2d_to_3d at this link, which says

Convert a 2D line to 3D

Looked promising to me, but I could not figure out how to use it.

Now, how would you modify the following code to achieve my objective?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

xs = np.linspace(0, 10, 100)
ys = np.linspace(0, 10, 100)

X, Y = np.meshgrid(xs, ys)
Z # ?????????

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
plt.show()

Thanks for you help in advance.

解决方案

Your mistake is that you define xs and ys as independent variables, while they are dependent (x + y = 5). zs is here independent:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

xs = np.linspace(0, 10, 100)
zs = np.linspace(0, 10, 100)

X, Z = np.meshgrid(xs, zs)
Y = 5 - X

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
plt.show()

Sample output:

这篇关于Matplotlib:如何在3D图形中绘制垂直平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆