matplotlib does not show my drawings although I ca

2019-01-02 19:25发布

I need your help about matplotlib. Yes, I did not forget calling the pyplot.show().

$ ipython --pylab

import matplotlib.pyplot as p 
p.plot(range(20), range(20))

It returns matplotlib.lines.Line2D at 0xade2b2c as the output.

p.show()

There is nothing to happen. No error message. No new window. Nothing. I install matplotlib by using pip and I didn't take any error messages.

Details:

I use,

  • Ubuntu
  • IPython v0.11
  • Python v2.6.6
  • matplotlib v1.0.1

14条回答
怪性笑人.
2楼-- · 2019-01-02 20:07

I had to install matplotlib from source to get this to work. The key instructions (from http://www.pyimagesearch.com/2015/08/24/resolved-matplotlib-figures-not-showing-up-or-displaying/) are:

$ workon plotting
$ pip uninstall matplotlib
$ git clone https://github.com/matplotlib/matplotlib.git
$ cd matplotlib
$ python setup.py install

By changing the backend, as @unutbu says, I just ran into loads more problems with all the different backends not working either.

查看更多
栀子花@的思念
3楼-- · 2019-01-02 20:10

%matplotlib inline

For me working with notebook, adding the above line before the plot works.

查看更多
美炸的是我
4楼-- · 2019-01-02 20:14

For me the problem happens if I simply create an empty matplotlibrc file under ~/.matplotlib on macOS. Adding "backend: macosx" in it fixes the problem.

I think it is a bug: if backend is not specified in my matplotlibrc it should take the default value.

查看更多
查无此人
5楼-- · 2019-01-02 20:15

I found that I needed window = Tk() and then window.mainloop()

查看更多
倾城一夜雪
6楼-- · 2019-01-02 20:16

For Ubuntu 12.04:

sudo apt-get install python-qt4
virtualenv .env --no-site-packages
source .env/bin/activate
easy_install -U distribute
ln -s /usr/lib/python2.7/dist-packages/PyQt4 .
ln -s /usr/lib/python2.7/dist-packages/sip.so .
pip install matplotlib
查看更多
查无此人
7楼-- · 2019-01-02 20:19

Similar to @Rikki, I solved this problem by upgrading matplotlib with pip install matplotlib --upgrade. If you can't upgrade uninstalling and reinstalling may work.

pip uninstall matplotlib
pip install matplotlib
查看更多
登录 后发表回答