Matplotlib plots not showing up on Mac OSX?

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

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

I run it, I get no error, but the image does not appear. On Linux Ubuntu, I get it.

Do you know what might be wrong here?

thank

+66
python matplotlib plot macos
Mar 24 '10 at 23:36
source share
12 answers

I can check it on my end too. To fix, here's what I did

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

In addition, we need to change the default base component to one of the graphical interfaces.

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

 backend: GTKCairo 



In addition, you can try the following, which may allow you not to use GTK or Cairo. Change ~/.matplotlib/matplotlibrc and add:

 backend: MacOSX 

If a port with these options is installed, this also works, but it does not require X11.




By the way, the error I saw was as follows:

 /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())) 
+45
Mar 25 '10 at 0:12
source share
— -

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

Easy solution - just check if you have

 plt.show() 

after the schedule

+88
Feb 13 '16 at 17:56
source share

This is what worked for me. I just changed the matplotlib import

 import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt 
+36
Aug 18 '15 at 20:30
source share

Upon attempt

 plt.savefig('myfilename.png') 

instead

 plt.show() 

Does this save the correct image named myfilename.png in the current path?

+10
Mar 24 '10 at 23:54
source share

just to add a note

The matplotlibrc file was missing on my system and I had to download a copy from the matplotlib website. Future users may have to do the same.

+3
Feb 02 '11 at 17:47
source share

This is what worked for me:

 brew install pkg-config brew link pkg-config brew install pygtk brew install freetype 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 

Literature:

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

+3
Jun 28 '13 at 16:57
source share

I only had python 2.5, and I did not want to install python 2.6 on my mac. Therefore, to solve this problem, I used another procedure specified in the following link:

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

What you really need are the following steps:

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

/ Opt / local / library / pkg-config

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

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

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

4) Replace the backend on MacOSX in a file and save it

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

 import matplotlib matplotlib.get_configdir() 
+2
Nov 04 2018-11-11T00:
source share

The Mac comes with its own Python ( read here , which is not the best), I would suggest just installing some Python 3.7 or so with Anaconda, and then presenting them as PyCharm interpreters. everything will work fine, and you don’t need to add special solutions like backend: macOSX or so.

+1
Jun 07 '19 at 18:05
source share

Do the following if someone is using spyder.

1.) Launch Spyder 2.3.5.2 from Anaconda Launcher 2.) Go to Settings → IPython Console → Graphics → Backend: change it to “Automatic” 3.) Select “Apply” and close the settings 3.) Restart the IPython kernel 4.) Creating simple graphics like

0
Mar 16 '18 at 17:27
source share

As a temporary work, you can save the picture in .png / .jpg / .pdf and use this file at 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') 
0
Feb 07 '19 at 17:31
source share
 sudo port install py37-matplotlib +cairo+gtk3 ~/.matplotlib/matplotlibrc used backend: MacOSX 

It seems to work on MacOS Mojave 10.14.4 with python 3.7 using the unicode_minus.py example above.

0
Mar 27 '19 at 3:05
source share

just copy this to your terminal:

 echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc 
-one
Dec 22 '17 at 9:22
source share



All Articles