Forgot your password?

Matplotlib For Python Developers 119

Posted by samzenpus
from the read-all-about-it dept.
Craig Maloney writes "Ever since there was a collection of numbers, it seems that invariably someone will want a graph of those numbers. There are literally hundreds of different styles of graphs, and almost as many programs and tools to make those graphs. Matplotlib, a library and toolkit for the Python language, provides an easy and effective way to make some impressive graphics with little more than a smattering of Python. Matplotlib for Python Developers is equally impressive at distilling the core set of features of Matplotlib in a way that shows the reader how to get the most out the Matplotlib toolkit." Read below for the rest of Craig's review.
Matplotlib for Python Developers
author Sandro Tosi
pages 291
publisher Packt Publishing
rating 9/10
reviewer Craig Maloney
ISBN 978-1-847197-90-0
summary A comprehensive overview of the powerful Matplotlib Python library
Matplotlib for Python Developers begins with the customary introduction to the Matplotlib library. It includes where to download Matplotlib, as well as brief installation instructions for both Linux, Macintosh, and Windows platforms. The book then quickly moves to the next chapter, where the basic library functions are presented, via the interactive iPython shell. Each section of the chapter introduces a new part of the graph, with items like titles, grid lines, and labels being explained clearly and concisely. Also briefly presented are other useful libraries like numpy, as well as the various back-ends that Matplotlib supports. Chapter 3 continues the even pace, presenting more plot styles, and plot types, including polar graphs. These two chapters cover the fundamentals of Matplotlib very well, with each step clearly marked by what the graph should look like once completed.

The next chapter introduces more advanced plotting concepts that Matplotlib is capable of handling. The chapter begins with the three ways that Matplotlib may be used (The pyplot module, pylab, and the Object Oriented interface). From there, the book delves into subplots, multiple figures, additional axes, logarithmic axes, date plotting, contour plots, and image plots. Also included are sections on using LaTeX and TeX with Matplotlib, both for exporting graphs, as well as using TeX inside plots via Mathtext. By the end of the chapter, I felt very comfortable with the environment and the capabilities of Matplotlib, both as an interactive environment, and as a module for my own programs.

The next four chapters cover integrating Matplotlib with GTK+, QT4, wxWidgets, and web-based environments. The chapters for GTK+, QT4, and wxWidgets each begin by presenting a basic overview of the toolkit, and why one might want to use that particular toolkit. Next, the book shows how to embed a Matplotlib figure in a window, both with static and real-time data input. The book then shows how to use the toolkit's builder with Matplotlib (Glade for GTK+, QT Designer for QT4, and wxGlade for wxWidgets. The chapter on web development veers slightly from this format by showing several examples of using CGI and mod_python with Matplotlib before showing how to use Matplotlib with Django and Pylons.

The last chapter pulls together some "real world" examples together for the grand finale. The examples clearly show how Matplotlib would work for such plotting Apache web logs, fitting curves, and plotting geographic data. The geographic data plotting uses an additional module called basemap, which allows for plotting precisely on a map. This example floored me with the amount of power that Matplotlib possesses.

Overall, I found this book to be informative, without a lot of fluff. The organization of the book sometimes dipped into a chaotic presentation of "oh, look at this", but overall the author kept a very even pace, with clearly defined goals and clean resolution of those goals. Matplotlib for Python Developers is definitely a book that I would pick up to refresh my memory for using Matplotlib. The asking price is a bit steep for book that is just shy of 300 pages, but overall I highly recommend it for anyone looking to get started with this exceptional library. I'd also recommend it for anyone looking for alternatives to some of the other plotting packages available. Matplotlib is quite powerful, and Matplotlib for Python Developers makes this power very accessible.

You can purchase Matplotlib for Python Developers from Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.


This discussion has been archived. No new comments can be posted.

Matplotlib For Python Developers

Comments Filter:
  • by Helmholtz Coil (581131) on Wednesday May 12, 2010 @03:41PM (#32185730) Journal

    That echoes my experience. I generally prefer Chaco [] for plots in Python since it seems to handle large datasets better than matplotlib (although matplotlib seems more functional), but matplotlib is comfortable for MATLAB users. I'm working on a SciPy project with a couple of MATLAB refugees and they love matplotlib.

  • by William Stein (259724) <> on Wednesday May 12, 2010 @03:47PM (#32185788) Homepage
    > I don't want to load 20 modules before I can begin coding. I just want to input my algorithm and get a result I expect (not 5/2=2). You might want to try Sage ( [] and []). It's Python, but it fixes the "5/2" issue and preloads numerous modules.
  • by matt_martin (159394) on Wednesday May 12, 2010 @03:59PM (#32185960) Homepage Journal

    Not even quite sure MATLAB "does what it does well". Its usually a great way to get started, especially if you don't quite know what you are doing. But then I often find myself wondering why I am working around bugs and re-writing functions in a $10k software package. Moved almost everything to python/numpy/scipy/Matplotlib over a year ago and really haven't looked back.

    Here's one thing that Matplotlib should not have replicated from MATLAB: insane memory usage.
    Please folks, lets get it under control: 1G of memory to display a med-large image is a joke !

  • by goombah99 (560566) on Wednesday May 12, 2010 @04:10PM (#32186110)

    Matplotlib which I use a lot, has really sucky documentation so this 250 pages would amount to basically all the documents. Additionally, you have to realize that matplot lib is not one coherent entity. it's a mish mash of many many things in numberical analysis much of it having to manage legacy cases and pertending to ape matlab syntax. So there's lots of special cases to cover.

    On the otherhand I really have ot wonder sometimes if matplotlib is a dead project. All of the standard distro's have 3D plotting that doesn't work anymore or depend on packages that are not maintained. The only modern 3d plotting in matplot lib is available through the enthought distro that folds in mayav. But since it does not support the full syntax of matplot lib and invents it's own new object structure, it's hard to write programs that one can distribute. Your end users may not be using enthought.

    Mat plot lib is wonderful because it lets matlab users switch to python. But it sucks because it seems like it's not being maintained well.

  • by WeatherGod (1726770) on Wednesday May 12, 2010 @04:22PM (#32186244)

    What result do you expect from 5/2? I expect 2... 5/2 == 2 in C, C++ and FORTRAN (I think... I don't write much FORTRAN code these days...)

    Just watch out in python 3.0, this will change. Because of python's duck-typing, you can never be certain if you were getting an integer or a float, and so it is possible to get different behaviors implicitly. Because python's mantra is "Explicit is better than Implicit", python 3.0 will only do integer (called floored) division when you do '//'.

  • by Discrete_infinity (192528) on Wednesday May 12, 2010 @04:50PM (#32186584)

    Yes, I saw that and had similar thoughts. Also they should look at virtual environment [] and look at Interactive python []

  • by yerM)M (720808) on Wednesday May 12, 2010 @05:40PM (#32187028) Homepage
    It's too bad they didn't use any in the book.

    I have used matplotlib for journal plots and actually gave away a copy at a conference I ran so I have to say I really do like the book overall, but if you scan through the pages, you might be turned off.

  • by BusterB (10791) on Wednesday May 12, 2010 @06:00PM (#32187194)
    When did they get rid of C-style string formatting? That's news to me.

    bcook@bcook-box:~$ python3
    Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> "%d %s" % (1, "Hello")
    '1 Hello'
  • by pclminion (145572) on Wednesday May 12, 2010 @06:20PM (#32187378)

    That's exactly the output you should expect for integer division, which is what 5/2 is asking for.

    On what planet? Just because C works that way, and Python works that way (at least until now), doesn't mean it's the best way, or the most useful way, or that it could never be changed.

    That's EXACTLY the point being made here -- people are touting Python as a scientific computing platform, but the result "5/2 == 2" is almost never what you want when doing scientific calculations. So from the standpoint of scientific coding, some features are really not ideal.

  • In Defense of Matlab (Score:3, Informative)

    by tobiah (308208) on Wednesday May 12, 2010 @07:09PM (#32187746)

    Python has it's strengths, but there are good reasons Matlab is so widely used:

    Price: There is a price to everything, Matlab's is up-front and what you get is guaranteed support and development. If there is a bug or serious shortcoming you know someone is working on it like their job depends on it.
    Graphics: Matlab has the most feature-rich and usable graphical environment of any of its would-be competitors, none of which do 3D well.
    Speed: Core Matlab operations are highly optimized in C; properly vectorized Matlab code will run much faster than what most programmers could write in C themselves.
    Interoperability: Java and .Net calls can be made from the Matlab command line, integrating compiled C is well-supported and very straightforward. Python can do these things, but it's not automatic or well-documented.
    Documentation: it's there, and it's good.
    Dev Environment: the debugging tools, profiler, and lint integration are really helpful.

  • by RichardJenkins (1362463) on Wednesday May 12, 2010 @07:16PM (#32187806)
    Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
    [GCC 4.4.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 5/2 #Diving integers in Python 2.6 gives an integer
    >>> from __future__ import division
    >>> 5/2 #Things work differently in the future
    >>> 5//2 #You can use a double '/' to explicitly force an integer in Python 3
  • by ceoyoyo (59147) on Thursday May 13, 2010 @10:31AM (#32193130)

    Yes, I have. The math stuff is just fine. The hardest part is usually installing LaTeX. The 3D stuff is unmaintained. There was some initial interest in it a few years ago and then it sort of died because there are other, better ways to plot in 3D. Even so, I believe the VTK integration still works reasonably well, and it just requires installing VTK and one other package. You might have a point that the third-party 3D addons to matplotlib are dead, but matplotlib itself certainly isn't.

    The best way to distribute a Python environment is to tar the whole thing up and send it to whomever. An alternative is just to tar up the site-packages directory. For a long time I had a separate, easily accessible site-packages that could be packaged and distributed to everyone in the lab on a regular basis. On OS X you can even make a pretty double click installer in about five minutes.

To do nothing is to be nothing.