最近使用python里的matplotlib库绘图,想在代码结束时显示图片看看,结果图片一闪而过,附上我原来代码:
1
2
3
4
5
6
7
8
|
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
...
...
#type(forecast)=< class 'pandas.core.frame.DataFrame'>
pic01=m.plot(forecast)
pic01.show()
|
我上网查了一下,在遇到show()方法无法显示图片或者图片一闪而过,解决方案分两步:
1.加头文件,完整头文件如下:
1
2
3
4
5
|
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from numpy import *
|
2.调用matplotlib.pyplot.show()方法:
完整代码为:
1
2
3
4
5
6
7
8
9
10
11
|
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from numpy import *
...
...
#type(forecast)=< class 'pandas.core.frame.DataFrame'>
pic01=m.plot(forecast)
plt.show() #是plt.show()而不是pic01.show()
pic01.savefig('temp.png') #存储图片,可选
|
以上这篇解决matplotlib库show()方法不显示图片的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/xiangxianghehe/article/details/72427060