用matplotlib绘制三维图形

2024-04-29 09:28:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python3.7,我试图创建一个3d图形,但是我看不到这个图形。 这是我的代码:

    from mpl_toolkits.mplot3d import axes3d
    fig=matplotlib.pyplot.figure()#creating a figure
    chart=fig.add_subplot(1,1,1,projection="3d")
    X,Y,Z=[1,2,3,4,5,6,7,8],[2,5,3,8,9,5,6,1],[3,6,2,7,5,4,5,6]
    chart.plot_wireframe(X,Y,Z)
    matplotlib.pyplot.show()

enter image description here 谢谢:)


Tags: 代码fromimportcreatingadd图形matplotlibchart
1条回答
网友
1楼 · 发布于 2024-04-29 09:28:29

不确定具体要绘制什么,但线框的z分量必须是二维的:

这是一个图:

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

fig = plt.figure()
chart = fig.add_subplot(1,1,1,projection="3d")
X, Y, Z = np.array([[1, 2, 3, 4, 5, 6, 7, 8], 
                    [2 ,5 ,3 ,8 ,9 ,5 ,6 ,1], 
                    np.array([[1, 2, 3, 4, 5, 6, 7, 8], [3, 6, 2, 7, 5, 4, 5, 6]])])
chart.plot_wireframe(X, Y, Z)
plt.show()

enter image description here


如果您想绘制一条曲线:

^{pr2}$

enter image description here

相关问题 更多 >