Matplotlib Save imshow array

半腔热情 提交于 2020-01-20 09:09:05

问题


I was wondering if it were at all possible to save the array of an imshow function? What do I mean by this?

Well, I have a 2d array with unique values. I would like to see that represented in colour, so I naturally would use the imshow function. I understand that the imshow function applies a colormap to my array and then displays that. I would like to be able to get the array that matplotlib uses to show my original 2d array in colour. Can this be done?


回答1:


You can actually just get the color maping with out imshow

data_ = (data - np.min(data))/ (np.max(data) - np.min(data))
my_cmap = matplotlib.cm.get_cmap('gray') # or what ever color map you want
color_array = my_cmap(data_)

color_array with be an array of shape data.shape + (4,), that is MxNx4 with the 4 being (r,g,b,a). Your data needs to be scaled to be in the range [0,1].



来源:https://stackoverflow.com/questions/14488188/matplotlib-save-imshow-array

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