Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't pyplot.show() work? [duplicate]

Possible Duplicate:
matplotlib does not show my drawings although I call pyplot.show()

I'm a newbie to Matplotlib and have encountered this problem. I'm using a Ubuntu system. I started with Matplotlib 0.99 and realized that I really need the new feature of "triplot" in the newer versions. So I downloaded the newest version by

git clone git://github.com/matplotlib/matplotlib.git

and installed it. However, when I work with python interactively, pyplot.show() does not show me the figure I plot, nor did it responded with any error message. pyplot.show() did work in the old version of matplotlib 0.99.

To be more specific, I seemed to have no problem importing "matplotlib" or modules inside the package; I can generate pdf files of a bunch of figures, but I just can't have the figure show up by typing pyplot.show() at the end of my code. Can anyone help me? Thank you!

like image 935
user1248468 Avatar asked Mar 04 '12 18:03

user1248468


People also ask

Is PLT show () necessary?

Plotting from an IPython shell Using plt. show() in Matplotlib mode is not required.

Why is my matplotlib plot not showing?

It means if we are not using the show() function, it wouldn't show any plot. When we use the show() function in the non-interactive mode. That means when we write the code in the file it will show all the figures or plots and blocks until the plots have been closed.

Why is matplotlib not working?

Matplotlib is not a built-in module (it doesn't come with the default python installation) in Python, you need to install it explicitly using the pip installer and then use it. If you looking at how to install pip or if you are getting an error installing pip checkout pip: command not found to resolve the issue.

What is Pyplot CLF ()?

The clf() function in pyplot module of matplotlib library is used to clear the current figure.


1 Answers

I had the same issue and solved it by setting the appropriate display backend, following matplotlib does not show my drawings although I call pyplot.show()

There are two ways to achieve this:

1.Set the backend in your code, right after importing matplotlib:

import matplotlib
matplotlib.rcParams['backend'] = "Qt4Agg"

2.Or define your backend inside your matplotlibrc file (as given by matplotlib.matplotlib_fname()):

backend      : Qt4Agg

More information here: http://matplotlib.sourceforge.net/users/customizing.html

like image 110
Régis B. Avatar answered Oct 16 '22 11:10

Régis B.