python - 在 matplotlib 中创建曲面并抛出线条

标签 python matplotlib

我尝试在 3 条线上创建曲面。 每条线由 3 个点定义(每个点都有坐标(x, y, z))

第一行: (0, 0, 10) (0,5,5) (0, 10, 2)

第二行: (2, 0, 10) (2,5,5) (2, 10, 2)

第三行: (4、1、10) (4,6,5) (4,11,2)

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 = [0, 2, 4, 0, 2, 4, 0, 2, 4]
y = [0, 0, 1, 5, 5, 6, 10, 10, 11]
z = [10, 10, 10, 5, 5, 5, 2, 2, 2]

X = x
Y = y
Z = z

Y, X = np.meshgrid(Y, X)
ax.plot_wireframe( X, Y, Z)
plt.show()

我得到了这张图片 my actual image

但我需要这样的图像: enter image description here

最佳答案

plot_trisurf 解决了我的问题。

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 = [0, 2, 4, 0, 2, 4, 0, 2, 4]
y = [0, 0, 1, 5, 5, 6, 10, 10, 11]
z = [10, 10, 10, 5, 5, 5, 2, 2, 2]

X = x
Y = y
Z = z

ax.plot_trisurf( X, Y, Z)
plt.show()

enter image description here

关于python - 在 matplotlib 中创建曲面并抛出线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28125000/

相关文章:

python - 阻止 gif 图像在 matplotlib 中重复

python - 为什么这个Python代码在我的类函数下不起作用?

python - Django 模型字段。自定义字段值 setter

python - 2 个子图共享 y 轴(之间没有空格)与单个颜色条

matplotlib - 如何根据定义的组为树状图的标签着色? (在Python中)

python - 用 python 绘制每日概况

python - 测试数据的 f1 分数

python - 属性错误 : 'tuple' object has no attribute 'autoscale_None'

python - 使用 GET 和 INCR 对 Redis 进行乐观锁定

python - 为什么时间是00 :00 when trying to plot them using matplotlib?