python-如何从plt.imshow()获取数据? [英] python - how to get the data from an plt.imshow()?
本文介绍了python-如何从plt.imshow()获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
import scipy.misc
import matplotlib.pyplot as plt
a = plt.imshow(scipy.misc.lena())
我希望实现的是通过访问 a
或它的孩子来获取有关lena的数据.
and what I'm hoping to achieve is get the data on lena by accessing a
or it's children.
原因是我将以 plt.gcf()
或 plt.gca()
推荐答案
a
应该是一个 matplotlib.image.AxesImage
实例,在这种情况下你可以使用>
a
should be a matplotlib.image.AxesImage
instance, in which case you can use
a.get_array()
和
a.set_array(data)
该数组存储为 masked数组
.
示例
http://matplotlib.org/examples/animation/dynamic_image 上有一个官方示例.html.
直接访问
您也可以使用
a._A
直接访问数组数据,尽管我认为 getter 和 setter 是首选方法.
to access the array data directly, though I imagine that the getters and setters are the preferred method.
这篇关于python-如何从plt.imshow()获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文