matplotlib 3d surface plots not showing [duplicate]

不羁的心 提交于 2019-11-28 01:29:32

You are not plotting a surface: x, y and z needs to be 2D arrays. Look at this example: http://matplotlib.org/examples/mplot3d/surface3d_demo.html.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D
from scipy.interpolate import griddata

x= np.arange(1, 100, 1)
y= np.arange(1, 100, 1)
z= np.arange(1, 100, 1)
fig = plt.figure()
ax = fig.gca(projection='3d')
xi = np.linspace(x.min(), x.max(), 50)
yi = np.linspace(y.min(), y.max(), 50)
zi = griddata((x, y), z, (xi[None, :], yi[:, None]), method='nearest')    # create a uniform spaced grid
xig, yig = np.meshgrid(xi, yi)
surf = ax.plot_wireframe(X=xig, Y=yig, Z=zi, rstride=5, cstride=3, linewidth=1)   # 3d plot
plt.show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!