linux下使用ipython的pylab模式時不顯示圖形的問題解決方案

來源:互聯網
上載者:User

在linux下使用ipython的pylab模式時發現使用matplotlib繪製的圖形並未之直接顯示出來,而且程式也沒有出現任何的錯誤提示,很是奇怪
google之後發現原始來matplot配置資訊的問題,通過調整matplotlibrc中的backend配置就可以輕鬆解決這一問題,解決方案如下:
(1)找出matplotlibrc的具體問題
  In [4]: import matplotlib
  In [5]: matplotlib.matplotlib_fname()
  Out[5]: '/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc'
(2)根據實際情況調整matplotlibrc配置
  vim /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc
  # 'module://my_backend'
  # backend      : Agg
  backend      : Qt4Agg

  # If you are using the Qt4Agg backend, you can choose here
  # to use the PyQt4 bindings or the newer PySide bindings to
  # the underlying Qt4 toolkit.
  # backend.qt4 : PyQt4        # PyQt4 | PySide
  backend.qt4 : PySide        # PyQt4 | PySide
對於backend的配置資訊,可以通過
  In [3]: import matplotlib.rcsetup as rcsetup
  In [4]: rcsetup.all_backends
來擷取所有支援的backend列表

按照上述方法修改matplotlibrc即可,此時再調用matplotlib繪製圖形的時候就可以看到圖形顯示視窗
需要注意的是:請根據具體環境設定backend,如果使用了qt也請根據實際情況設定backend.qt4是使用的PyQt4還是PySide

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.