停了兩個月課的小韓同學終於又開始學習數據分析了...剛一上課就遇到了很多環境問題...
問題一:
環境中已經安裝了matplotlib庫仍然報了No module named matplotlib.pyplot的錯誤。
csdn解決方法一:重裝matplotlib庫
pip uninstall matplotlibpip install matplotlib但是操作之後仍是報同樣錯誤。
csdn解決方法二:在導入matplotlib庫後,且在matplotlib.pyplot庫被導入前加「matplotlib.use(『agg』)」語句。
import numpy as npimport matplotlibmatplotlib.use('agg')import matplotlib.pyplot as plt # matplotlib.use('agg')必須在本句執行前運行成功解決~
問題二:
python中使用matplotlib庫畫圖失敗
運行程序後報錯如下:
UserWarning:Matplotlib is currently using agg, which is a non-GUI backend, so cannot showthe figure.
解決方法:在開頭加上下列代碼
import matplotlib; matplotlib.use('TkAgg')兩個問題解決完畢,最終代碼如下:
import matplotlibmatplotlib.use('agg')import matplotlib.pyplot as plt
import matplotlib; matplotlib.use('TkAgg')今日份學習記錄——數據可視化matplotlib庫,工具:jupyter notebook: