Make a 2D pixel plot with matplotlib

落爺英雄遲暮 提交于 2019-11-27 07:17:11
Joe Kington

Based on the way it looks like your x,y,temp triples are ordered (listed out in rows), you can just reshape the "temp" column.

E.g.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

x,y,temp = np.loadtxt('data.txt').T #Transposed for easier unpacking
nrows, ncols = 100, 100
grid = temp.reshape((nrows, ncols))

plt.imshow(grid, extent=(x.min(), x.max(), y.max(), y.min()),
           interpolation='nearest', cmap=cm.gist_rainbow)
plt.show()

hsv is the "rainbow" colormap you were referring to. Edit: You probably actually wanted matplotlib.cm.gist_rainbow. matplotlib.cm.hsv goes back to red at the bottom. See here: https://matplotlib.org/users/colormaps.html for a list of colormaps.

If your x,y,temp triplets aren't actually ordered, then you'll need to regrid your points. I showed an example of this in my answer to your previous question.

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