Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib plots not showing up in Mac OSX?

I am running Mac OSX 10.5.8. I installed matplotlib using macports. I get some examples from the matplotlib gallery like this one, without modification:

http://matplotlib.sourceforge.net/examples/api/unicode_minus.html

I run it, get no error, but the picture does not show up. In Linux Ubuntu I get it.

Do you know what could be wrong here?

like image 270
Open the way Avatar asked Mar 24 '10 23:03

Open the way


People also ask

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.

Does matplotlib work on Mac?

If you are using Python from https://www.python.org, Homebrew, or Macports, then you can use the standard pip installer to install Matplotlib binaries in the form of wheels. ( sudo python3. 6 ... on Macports). You might also want to install IPython or the Jupyter notebook ( python3 -mpip install ipython notebook ).

Why is matplotlib Pyplot not working?

The ImportError: No module named matplotlib. pyplot occurs if you have not installed the Matplotlib library in Python and trying to run the script which has matplotlib related code. Another issue might be that you are not importing the matplotlib. pyplot properly in your Python code.


2 Answers

I had the same problem, even I could see how a new application window was created and immediately disappeared.

Simple solution - just check if you have

# Assumes you have imported "matplotlib.pyplot" as "plt" plt.show() 

after the plot

like image 68
layser Avatar answered Oct 13 '22 04:10

layser


I can verify this on my end as well. To fix, here's what I did

sudo port install py25-matplotlib +cairo+gtk2 sudo port install py26-matplotlib +cairo+gtk2 

Also, we need to change the default backend to a GUI based one.

Edit the file ~/.matplotlib/matplotlibrc, and add:

backend: GTKCairo 

Also, you can try the following, which may allow you to not need the GTK or Cairo backends. Edit ~/.matplotlib/matplotlibrc and add:

backend: MacOSX 

With the port with those variants installed, this works as well, but it doesn't require X11.


By the way, the error that I saw was the following:

/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/__init__.py:41: UserWarning:  Your currently selected backend, 'Agg' does not support show(). Please select a GUI backend in your matplotlibrc file ('/Users/wlynch/.matplotlib/matplotlibrc') or with matplotlib.use() (backend, matplotlib.matplotlib_fname())) 
like image 35
Bill Lynch Avatar answered Oct 13 '22 06:10

Bill Lynch