Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

In my case, plot was showing initially then stopped as I was installing couple of other packages like pandasql, boxsdk etc[not sure, what broke it]. Re-installing matplotliib resolved my issue. Lot of good suggestions/fixes can be found at the answers. If none of the them helps, before give up, try re-install matplotlib. Robert Ranjan Jul 7, 2019 at 3:55

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

This worked for me also using pandas plot and thenimport matplotlib.pyplot as plt and then let it show up. It's a bit strange but it worked fine! – Allan Karlson Jul 10, 2017 at 7:24 This was the solution to getting plots showing in PyCharm 2018.1 (running on OSX) in the Scientific mode tab (SciView) as well! – neurozen Apr 26, 2018 at 0:46 The reason this works is to do with interactive vs non-interactive mode. If the backend is opened in non-interactive mode, plt.show() is required at the end of the code chunk. You can check the status by calling plt.isinteractive() and toggle the status using plt.ion() and plt.ioff() – nphadke Sep 8, 2018 at 17:39

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()))
                I had to add the file matplotlibrc b\c it wasn't there. I used the MacOSX backend successfully.
– SargeATM
                Nov 30, 2011 at 16:27
                I've set matplotlib.use("TkAgg") after all the imports, and it still works fine, so I don't think the order is important here.
– retif
                Sep 5, 2020 at 17:00
                A correction to my previous comment - in works like this with the latest matplotlib versions, but in older versions you indeed had to do that before importing.
– retif
                Sep 15, 2020 at 20:09
                Also: this suggests (for the 'not showing up' part) that you may need to have a matplotlibrc file (search for it first) and change the backend to tkAgg: newmediaandcapitalmarkets.org/component/content/article/… . Which python are you using?
– ChristopheD
                Mar 25, 2010 at 0:01
                @nphadke - Using plt.show() - I got my plot to show , then I tried before my plt.legend(), I did plt.ion() - and removed plt.show(), and I got my plt.isinteractive() to print True, but still I didn't get my plot to show. So, where should one do plt.ion() to switch to interactive mode - if somebody just wanted to check if this works or not without using plt.show()?
– aspiring1
                Nov 3, 2020 at 5:31
brew install libpng
sudo ln -s /usr/local/Cellar/freetype/*/lib/pkgconfig/freetype2.pc /usr/local/lib/pkgconfig/freetype2.pc
git clone git@github.com:matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install

References:

http://blog.caoyuan.me/2012/08/matplotlib-error-mac-os-x/ http://matplotlib.org/faq/installing_faq.html#install-from-git http://www.tapir.caltech.edu/~dtsang/python.html

this in combination with putting backend: tkAgg in ~/.matplotlib/matplotlibrc worked for me – Collin Jun 2, 2016 at 3:39 Thanks a ton! After all the agonising roaming around in google, finally this solved the issue for me! – hi15 Sep 7, 2016 at 6:09

I only had python 2.5 and I did not want to install python 2.6 on my mac. So I used different procedure mentioned in the following link to solve this problem:

http://www.gtkforums.com/viewtopic.php?f=3&t=54928

What that one actually needs is the following steps:

1) Searching where is the directory "pygtk-2.0.pc" and locate it. For example mine was located in the following directory:

/opt/local/lib/pkgconfig

2) Adding the path information to envirement variable. For example:

PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
export PKG_CONFIG_PATH

3) Download the configuration information file "matplotlibrc" from matplotlib website http://matplotlib.sourceforge.net/_static/matplotlibrc

4) Change backend to MacOSX in the file and save it

5) Copy the file to directory .matplotlib You can locate the directory in python by the following command:

import matplotlib
matplotlib.get_configdir()

Mac comes with its own python (read from here, which is not the best), I would suggest just a clean install of some Python 3.7 or so along with Anaconda and then introduce them as interpreters to PyCharm. anything will work fine and you wont need to add ad-hoc solutions like "backend: MacOSX" or so.

Do the following if anyone is using spyder.

1.) Start Spyder 2.3.5.2 from Anaconda Launcher 2.) Go to preferences -> IPython console -> Graphics -> Backend: changed it to "Automatic" 3.) Select "Apply" and close preferences 3.) Restart IPython kernel 4.) Create simple graphic like

As a temporary work around one can save the figure to a .png/.jpg/.pdf and make use of that file for the moment.

## assuming price is out DataFrame that contains columns that we want to plot 
pdf_plot=price.plot().get_figure()  
pdf_plot.savefig('Stocks.pdf')
sudo port install py37-matplotlib +cairo+gtk3
~/.matplotlib/matplotlibrc used 
backend: MacOSX

Seemed to work on MacOS Mojave 10.14.4 with python 3.7 on the unicode_minus.py example above.