plt/sns draw histgram

Posted dulun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了plt/sns draw histgram相关的知识,希望对你有一定的参考价值。

当使用如下代码保存使用 plt.savefig 保存生成的图片时,结果打开生成的图片却是一片空白。

import matplotlib.pyplot as plt
x = np.triu(ged) # get the upper triangle matrix x = x.flatten() # glatten x=x[np.nonzero(x)] # remove zeros. sns.distplot(x, kde=False, rug=True) plt.show() plt.savefig("hist_ged.png")

原因

其实产生这个现象的原因很简单:在 plt.show() 后调用了 plt.savefig() ,在 plt.show() 后实际上已经创建了一个新的空白的图片(坐标轴),这时候你再 plt.savefig() 就会保存这个新生成的空白图片。

 

以上是关于plt/sns draw histgram的主要内容,如果未能解决你的问题,请参考以下文章