Plot a 3d surface from a 'list of lists' using matplotlib

最后都变了- 提交于 2019-12-04 10:26:08

if you want a 3d-surface, you have to generate x and y coordinates. If you don't care what they are and just want the surface, generate a meshgrid of integers in the given length:

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


data = np.array(data)
length = data.shape[0]
width = data.shape[1]
x, y = np.meshgrid(np.arange(length), np.arange(width))

fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
ax.plot_surface(x, y, data)
plt.show()

please refer to http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html and http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb for further information

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