Python 从matplotlib fig对象获取xy数据

Python 从matplotlib fig对象获取xy数据,python,matplotlib,Python,Matplotlib,我需要从具有2个子图的fig对象检索XY数据 以下是我制作fig对象的方式: f, axarr = plt.subplots(1,2) axarr[0].imshow(labels_map,vmax=28) axarr[1].imshow(Y_predictions,vmax=28) np.save('fig.npy', f) 我无法重新制作无花果对象,因为我再也无法访问该机器 从以前的stackoverflow post: fig = numpy.load("fig.npy").item()

我需要从具有2个子图的fig对象检索XY数据

以下是我制作fig对象的方式:

f, axarr = plt.subplots(1,2)
axarr[0].imshow(labels_map,vmax=28)
axarr[1].imshow(Y_predictions,vmax=28)
np.save('fig.npy', f)
我无法重新制作无花果对象,因为我再也无法访问该机器

从以前的stackoverflow post:

fig = numpy.load("fig.npy").item()
ax = fig.gca()
xy_data = ax.get_lines()
print(xy_data[0])
打印失败:列表索引超出范围

我需要获得两个子批次的2d数组,以便生成混淆矩阵。

尝试以下操作

xy_data = ax.get_lines()[0].get_data()
print (xy_data)

你的情节中没有线条;但是图像。因此,

import matplotlib.pyplot as plt
import numpy as np

f, axarr = plt.subplots(1,2)
axarr[0].imshow(np.random.randint(0,28, (10,10)),vmax=28)
np.save('fig.npy', f)
plt.close()

fig = np.load("fig.npy").item()
data = fig.axes[0].images[0].get_array()
print(data)

结果是:@Paku:对不起,请检查编辑。我是从phonexy_data=ax.get_lines[0]写的。get_data indexer:list index超出范围xy_data=ax.get_lines.get_data AttributeError:“silent_list”对象没有属性“get_data”@Paku执行lenax.get_lines时会得到什么。所以现在我觉得自己在文档中找不到它很愚蠢。一个真正的RTFM时刻。