[英]plotting 3d graph using matplotlib
im ysing python 3.7 and i tried to creat a 3d graph but i cant see the graph . 即时通讯python 3.7,我尝试创建3d图形,但看不到该图形。 this is my code : 这是我的代码:
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()
Not sure what exactly you want to plot, but the z component of a wireframe must be two dimensional: 不确定要绘制的内容到底是什么,但是线框的z分量必须是二维的:
this shows a plot: 这显示了一个情节:
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()
If instead, you wanted to plot a curve: 如果相反,您想绘制一条曲线:
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],
[3, 6, 2, 7, 5, 4, 5, 6]])
chart.plot(X, Y, Z)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.