最近使用python里的matplotlib庫繪圖,想在代碼結(jié)束時(shí)顯示圖片看看,結(jié)果圖片一閃而過,附上我原來代碼:
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() |
我上網(wǎng)查了一下,在遇到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.調(diào)用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') #存儲(chǔ)圖片,可選 |
以上這篇解決matplotlib庫show()方法不顯示圖片的問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/xiangxianghehe/article/details/72427060