简体   繁体   English

Matplotlib show() 和 savefig() 不一致

[英]Matplotlib show() and savefig() inconsistent

Code below should show the same image (green background) both when using.savefig() and.show(), but the savefig image is blank.下面的代码在使用 .savefig() 和 .show() 时应该显示相同的图像(绿色背景),但 savefig 图像是空白的。 I know that.show() clears the figures but I call it after.savefig(), so it isn't the case here.我知道.show() 清除了数字,但我在.savefig() 之后调用它,所以这里不是这种情况。 Both plt.savefig() and fig.savefig() produce the same blank image. plt.savefig() 和 fig.savefig() 都产生相同的空白图像。

Code (I'm using Python 3.6.8):代码(我使用的是 Python 3.6.8):

from matplotlib import pyplot as plt

def test(dpi=100):
    fig = plt.figure(figsize=(12.8, 7.2), dpi=dpi)
    fig.patch.set_facecolor('#a8bc95')
    plt.savefig("test.png")
    plt.show()

test()

.show() 。节目()

.savefig() .savefig()

Updating the matplotlib version fixes the problem.更新 matplotlib 版本修复了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM