解決PyCharm無法顯示matplotlib繪圖問題

來源:互聯網
上載者:User

解決PyCharm無法顯示matplotlib繪圖問題

最近開始接觸matplotlib,

1.首先安裝matplotlib庫和其依賴的一些其他庫,例如:numpy,scipy和pandas等

2.開始進行簡單的編碼工作,並在PyCharm中運行,出現如下錯誤:

Traceback (most recent call last):
  File "J:/MyGit/pythonTest/GetTegeather/test06.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "J:\software\PyCharm 2017.3.1\helpers\pycharm_matplotlib_backend\backend_interagg.py", line 17, in <module>
    verbose = matplotlib.verbose
AttributeError: module 'matplotlib' has no attribute 'verbose'

解決步驟如下:

前提:

1.匯入正確版本的matplotlib庫

2.代碼最後調用matplotlibku中pyplot.show()方法

3,無其他低級錯誤

解決步驟:

1.在匯入pyplot之前.需要輸入如下步驟:

  import matplotlib as mpl

  mpl.use('Agg')

  import matplotlib.pyplot as plt

  ....

2.此時運行python程式,雖然不報錯,但是並沒有繪圖介面彈出

  在命令號幾面輸入如下命令:

  import matplotlib

  print(matplotlib.get_backend())

  將得到的字串結果替換mlp.use('Agg')中Agg'即可

  例如:我的print(matplotlib.get_backend())結果為TkAgg,替換後為:

  mpl.use('TkAgg')

3.顯示正常

4.至於原因,個人能力有限,無法解釋透徹,

有大神直接更改matplotlibrc檔案中backend的值(backend選項改成你系統的圖形環境),有興趣的自行摸索

本文永久更新連結地址:https://www.bkjia.com/Linux/2018-03/151117.htm

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.