Book Image

Matplotlib for Python Developers

Book Image

Matplotlib for Python Developers

Overview of this book

Providing appealing plots and graphs is an essential part of various fields such as scientific research, data analysis, and so on. Matplotlib, the Python 2D plotting library, is used to produce publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. This book explains creating various plots, histograms, power spectra, bar charts, error charts, scatter-plots and much more using the powerful Matplotlib library to get impressive out-of-the-box results. This book gives you a comprehensive tour of the key features of the Matplotlib Python 2D plotting library, right from the simplest concepts to the most advanced topics. You will discover how easy it is to produce professional-quality plots when you have this book to hand. The book introduces the library in steps. First come the basics: introducing what the library is, its important prerequisites (and terminology), installing and configuring Matplotlib, and going through simple plots such as lines, grids, axes, and charts. Then we start with some introductory examples, and move ahead by discussing the various programming styles that Matplotlib allows, and several key features. Further, the book presents an important section on embedding applications. You will be introduced to three of the best known GUI libraries 'GTK+, Qt, and wxWidgets' and presented with the steps to implement to include Matplotlib in an application written using each of them. You will learn through an incremental approach: from a simple example that presents the peculiarities of the GUI library, to more complex ones, using GUI designer tools. Because the Web permeates all of our activities, a part of the book is dedicated to showing how Matplotlib can be used in a web environment, and another section focuses on using Matplotlib with common Python web frameworks, namely, Pylons and Django. Last, but not least, you will go through real-world examples, where you will see some real situations in which you can use Matplotlib.
Table of Contents (14 chapters)
Matplotlib for Python Developers
Credits
About the Author
About the Reviewers
Preface

About dependencies


As mentioned earlier, Matplotlib has its origin in scientific fields, so it is commonly used to plot huge datasets. Python's native support for long lists becomes impractical for such sizes, so Matplotlib needs better support for arrays.

NumPy, the de facto standard Python module for numerical elaborations, provides support for high performance operations even with big mathematical data types such as arrays or matrices—along with many other mathematical functions that can be useful to Matplotlib users.

NumPy has to be available to use Matplotlib.

Once we have chosen the set of user interfaces (UIs) we prefer, then we need to install the Python bindings for them. Here is a summarizing list:

User Interface (UI)

Binding

Version

Description

FLTK

pyFLTK

1.0 or higher

pyFLTK provides Python wrappers for the FLTK widgets library for use with FLTKAgg backend.

GTK+

PyGTK

2.2 or higher

PyGTK provides Python wrappers for the GTK+ widgets library to use it with the GTK or GTKAgg backend.

It is recommended to use a version higher than 2.12, for a correct memory management.

Qt

PyQt or PyQt4

3.1 or higher and for Qt4, 4.0 or higher

PyQt or PyQt4 provides Python wrappers for the Qt toolkit and is required by the Matplotlib QtAgg and Qt4Agg backends. The library is widely used on Linux and Windows.

Tk

PyTK

8.3 or higher

Python wrapper for Tcl or Tk widgets library is used in TkAgg backend.

Wx

wxPython

2.6 or higher, or

2.8 or higher

wxPython provides Python wrappers for the wxWidgets library for use with the WX and WXAgg backends. It is widely used on Linux, Mac OS X, and Windows.

Another important tool, in particular for interactive usage, is IPython. It's an interactive Python shell with a lot of useful features, such as history, commands repeating, and others. It already has a Matplotlib mode in it. We'll be using IPython in this book, so it is recommended to install it.

Some of the tools that are needed by Matplotlib are already shipped with it (in the source code as well as in the binary distributions). Here is the list of those tools:

  • AGG (version 2.4): This is the Anti-Grain Geometry rendering engine. The local copy of the library is linked with the Matplotlib code in a static way. So, there's no need to install it (as a shared library).

  • pytz (version 2007g or higher): This is used for handling the time zone for datetime Python objects. It will be installed if it's not already present in the system. It can be overridden using setup.cfg.

  • python-dateutil (version1.1 or higher): This is used for enhanced handling of the datetime Python objects. It needs to be installed if it's not already present in the system and can be overridden using setup.cfg.

Build dependencies

The following tools are needed if we're going to install Matplotlib from the source:

  • Python: Currently, only Python 2.x is supported (no Python 3 yet)

  • NumPy: Version 1.1 or higher

  • libpng: Version 1.1 or higher is needed to load or save PNG images (Windows users can skip this requirement)

  • FreeType: Version 1.4 or higher is needed for reading TrueType font files (Windows users can skip this requirement)

Note

libpng and FreeType for Windows users are already packaged in the Matplotlib Windows installer.