保存熊猫相关矩阵,而不是显示它

时间:2020-04-04 00:39:02

标签: python pandas matplotlib

我想保存熊猫关联矩阵而不是显示它。 这是我尝试过的代码。此代码显示图像并保存。我只想保存相关图,但不想显示它。

for subject in range(len(train)):
  for trial in range(subject):
    df = pd.DataFrame(train[subject][trial], columns=channels)
    img=plt.matshow(df.corr())
    plt.savefig('train_images/result_{}_{}.png'.format(subject,trial), bbox_inches='tight', pad_inches=0.0)

谢谢!

1 个答案:

答案 0 :(得分:1)

我猜您在Jupyter笔记本中的代码是%matplotlib inline。然后,您可以放

plt.close()

plt.savefig(...)之后,以防止将该图形嵌入到笔记本中。