Blog

Python MatPlotLib on MacOS

To accompany NumPy and PyLab we need a way of producing graphical output and the prefered route is MatPlotLib. The problem is that the ‘out of the boxpip installation on MacOS creates a slightly unfriendly configuration which means graphs don’t display without a ‘.show()’ command and then they’re in blocking mode so you cannot close them without a winge or two.

Assuming you are using the version of Python that comes pre-installed with MacOS. Unless already installed, install pip using:

sudo easy_install pip

There may be a complaint about the cache being owned by someone else, this is because the case is owned by you and you’re running the installer as root. I found that installing using sudo meant a smoother installation of Python libraries.

You can keep it up to date using:

sudo pip –update

Install the statistics libraries

sudo pip install numpy

sudo pip install pylab

sudo pip install matplotlib

To overcome the problem with displaying graphs, if it doesn’t already exist create a folder:

mkdir ~/.matplotlib

and create a file:

~/.matplotlib/matplotlibrc

that contains a single line

backend: TkAgg

the reason for this is the default backend for matplotlib is MacOSX which doesn’t seem to work.

 

Please note that this solution was eventually found on StackOverFlow and kindly provided by j4ck (14th Feb 2014).

© Mick Vaites 2018