美文网首页python自学
Python: matplotlib.pyplot.savefi

Python: matplotlib.pyplot.savefi

作者: 正在学习的Yuki | 来源:发表于2019-07-05 23:25 被阅读2次

Error:plt.savefig() 输出空白图片

代码

import matplotlib.pyplot as plt
...
plt.imshow(image.read_value()[0])
plt.show()
plt.savefig('xxx.png')

原因

plt.show() 之后会新建一个空白的图像(plt),其后的代码将画在这个空白图像上,所以保存的图像是空白的。

解决方案

先保存图片,最后show,即:将 plt.savefig() 放在 plt.show() 之前。

plt.imshow(image.read_value()[0])
plt.savefig('xxx.png')
plt.show()

Reference: https://stackoverflow.com/questions/9012487/matplotlib-pyplot-savefig-outputs-blank-image

相关文章

网友评论

    本文标题:Python: matplotlib.pyplot.savefi

    本文链接:https://www.haomeiwen.com/subject/rgqyhctx.html