There are many different ways to install matplotlib, and the best way depends on what operating system you are using, what you already have installed, and how you want to use it. To avoid wading through all the details (and potential complications) on this page, the easiest thing for you to do is use one of the pre-packaged python distributions that already provide matplotlib built-in. The Enthought Python Distribution (EPD) for Windows, OS X or Redhat is an excellent choice that “just works” out of the box. Another excellent alternative for Windows users is Python (x, y) which tends to be updated a bit more frequently. Both of these packages include matplotlib and pylab, and lots of other useful tools. matplotlib is also packaged for almost every major Linux distribution. So if you are on Linux, your package manager will probably provide matplotlib prebuilt.
For some people, the prepackaged pythons discussed above are not an option. That’s OK, it’s usually pretty easy to get a custom install working. You will first need to find out if you have python installed on your machine, and if not, install it. The official python builds are available for download here, but OS X users please read Which python for OS X?.
Once you have python up and running, you will need to install numpy. numpy provides high-performance array data structures and mathematical functions, and is a requirement for matplotlib. You can test your progress:
>>> import numpy >>> print numpy.__version__
matplotlib requires numpy version 1.4 or later. Although it is not a requirement to use matplotlib, we strongly encourage you to install ipython, which is an interactive shell for python that is matplotlib-aware.
Next, we need to get matplotlib installed. We provide prebuilt binaries for OS X and Windows on the matplotlib download page. Click on the latest release of the “matplotlib” package, choose your python version (2.6, 2.7 or 3.2) and your platform (macosx or win32). If you have any problems, please check the Installation, search using Google, and/or post a question the mailing list.
If you are on Debian/Ubuntu linux, it suffices to do:
> sudo apt-get install python-matplotlib
Instructions for installing our OSX binaries are found in the FAQ Installing OSX binaries.
Once you have ipython, numpy and matplotlib installed, you can use ipython’s “pylab” mode to have a MATLAB-like environment that automatically handles most of the configuration details for you, so you can get up and running quickly:
johnh@flag:~> ipython -pylab Python 2.4.5 (#4, Apr 12 2008, 09:09:16) IPython 0.9.0 -- An enhanced Interactive Python. Welcome to pylab, a matplotlib-based Python environment. For more information, type 'help(pylab)'. In : x = randn(10000) In : hist(x, 100)
Note that when testing matplotlib installations from the interactive python console, there are some issues relating to user interface toolkits and interactive settings that are discussed in Using matplotlib in a python shell.
If you don’t already have python installed, you may want to consider using the Enthought edition of python, which has scipy, numpy, and wxpython, plus many other useful packages, preinstalled - Enthought Python. With the Enthought edition of python + matplotlib installer, the following backends should work out of the box: agg, wx, wxagg, tkagg, ps, pdf and svg.
For standard python installations, you will also need to install numpy in addition to the matplotlib installer. On some systems you will also need to download msvcp71.dll library, which you can download from http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71 or other sites. You will need to unzip the archive and drag the dll into c:windowssystem32.
All of the GUI backends run on Windows, but TkAgg is probably the best for interactive use from the standard python shell or ipython. The Windows installer (*.exe) on the download page contains all the code you need to get up and running. However, there are many examples that are not included in the Windows installer. If you want to try the many demos that come in the matplotlib source distribution, download the zip file and look in the examples subdirectory.
If you are interested in contributing to matplotlib development, running the latest source code, or just like to build everything yourself, it is not difficult to build matplotlib from source. Grab the latest tar.gz release file from the download page, or if you want to develop matplotlib or just need the latest bugfixed version, grab the latest git version Source install from git.
Once you have satisfied the requirements detailed below (mainly python, numpy, libpng and freetype), you can build matplotlib:
cd matplotlib python setup.py build python setup.py install
We provide a setup.cfg file that goes with setup.py which you can use to customize the build process. For example, which default backend to use, whether some of the optional libraries that matplotlib ships with are installed, and so on. This file will be particularly useful to those packaging matplotlib.
If you have installed prerequisites to nonstandard places and need to inform matplotlib where they are, edit setupext.py and add the base dirs to the basedir dictionary entry for your sys.platform. e.g., if the header to some required library is in /some/path/include/someheader.h, put /some/path in the basedir list for your platform.
These are external packages which you will need to install before installing matplotlib. Windows users only need the first two (python and numpy) since the others are built into the matplotlib Windows installers available for download at the download page <https://github.com/matplotlib/matplotlib/downloads>_. If you are building on OSX, see Building on OSX. If you are installing dependencies with a package manager on Linux, you may need to install the development packages (look for a “-dev” postfix) in addition to the libraries themselves.
If you are on debian/ubuntu, you can get all the dependencies required to build matplotlib with:
sudo apt-get build-dep python-matplotlib
If you are on Fedora/RedHat, you can get all the dependencies required to build matplotlib by first installing yum-builddep and then running:
su -c "yum-builddep python-matplotlib"
This does not build matplotlib, but it does get the install the build dependencies, which will make building from source easier.
These are optional packages which you may want to install to use matplotlib with a user interface toolkit. See What is a backend? for more details on the optional matplotlib backends and the capabilities they provide.
Required libraries that ship with matplotlib
The build situation on OSX is complicated by the various places one can get the libpng and freetype requirements (darwinports, fink, /usr/X11R6) and the different architectures (e.g., x86, ppc, universal) and the different OSX version (e.g., 10.4 and 10.5). We recommend that you build the way we do for the OSX release: get the source from the tarball or the git repository and follow the instruction in README.osx.