Follow Slashdot stories on Twitter


Forgot your password?

Matplotlib For Python Developers 119

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 Animats ( 122034 ) on Wednesday May 12, 2010 @02:28PM (#32184956) Homepage

    This is something that ought to be one chapter in a Python book, not another boat-anchor of a standalone book.

  • by Thelasko ( 1196535 ) on Wednesday May 12, 2010 @02:56PM (#32185252) Journal
    I've heard quite a few people here on Slashdot talk about how useful Python is as a substitute for MATLAB. Honestly, I don't get it. Python is trying to be a language for both hard core programming, and scientific programing. These two disciplines have very different needs. 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).

    It seems that version 3.0 has gotten better for us scientific users. However, I think the programmers out there are now dissatisfied.
  • by kolabaum ( 1810138 ) on Wednesday May 12, 2010 @03:14PM (#32185380)
    I would consider Octave to be a much better substitute for MATLAB rather than Python for those who just wants to 'get the job done'. That being said, however, I think anyone who uses Python for scientific work (for whatever reason) would greatly appreciate Matplotlib due to the resemblance to MATLAB's built-in plot functions.
  • by fuzzyfuzzyfungus ( 1223518 ) on Wednesday May 12, 2010 @03:15PM (#32185388) Journal
    Does loading those twenty modules hurt you if, by virtue of their being in common use, there is some trivial automated way of doing it?

    With the exception of people writing bare-metal assembly for microcontrollers or something, pretty much everyone who sits down to write some code has huge swaths of pre-written stuff loaded for them. The only difference is how much of that happens automatically, by default, and how much you see and do yourself.

    If the science types happen to like python for some syntactic or structural or design reasons; but need a bunch of modules to make it do what they want, it isn't exactly rocket surgery to bundle them all together so a single "import science" does the job, or even hack together a slight variant of the python environment where that particular import is simply done silently by default.
  • by radtea ( 464814 ) on Wednesday May 12, 2010 @03:21PM (#32185474)

    I just want to input my algorithm and get a result I expect (not 5/2=2).

    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...)

    Python does an excellent job of making both useful scientific functionality available via scipy and numpy and a wealth of other toolkits, and at the same time allowing us to package stuff up in usable applications. It provides all the real-world applications language facilities that MATLAB, Mathematica, R, etc lack.

    I deal with people who "code" in those environments all the time, and they are not my peers: they have fundamentally failed to grasp almost everything important about programming, from design principles to documentation. For someone who knows how to write software--which MATLAB et al "programmers" do not, as a professional understands the term--Python is pretty much ideal for expressing algorithms and wrapping them in useful applications.

  • by honkycat ( 249849 ) on Wednesday May 12, 2010 @03:45PM (#32185762) Homepage Journal

    I use Python for scientific computing and much, much, much prefer it to MATLAB. Most of what I do does not require sophisticated library routines, and the sophisticated stuff I do need generally either aren't common enough to exist for MATLAB or are quirky enough that I wouldn't trust someone else's library to have the details right. Thus, the typically cited advantages of MATLAB are not there for me. Python provides a much better thought out programming language. It's sometimes a bit less convenient for interactivity, but really I got used to using it (plus matplotlib an numpy) quickly and I have not felt the urge to move back to MATLAB for quite some time. Very occasionally I'll pop in to do a crude curve fit, but not often.

    The needs of scientific programming and hard core programming (whatever exactly that means) are not so different. As for not wanting to load modules, um, what? I can think of reasonable complaints about Python, but I don't consider that among them. That reeks of "it's different so I don't like it," which is not a well thought through reason.

  • by mangu ( 126918 ) on Wednesday May 12, 2010 @04:28PM (#32186312)

    I don't want to load 20 modules before I can begin coding.

    That's why I don't like Matlab. Not only you have to import every single function you use, but each function comes in a separate file. And when you find the function you need on the web, you have to shell out an extra $5k to get the libraries it depends on.

    My only worry about Python is that version 3 abomination. They not only managed to make each change towards a more complicated way to use, but also deprecated such a basic thing as string formatting. About one third of the code I write is related to text I/O, so a quick and easy way to format strings is very near the top priority on any language.

    Last time I checked there are ten times as many references to the C language on Google as references to Python, so I cannot imagine why they want to get rid of the C-compatible string formatting. They created something that, in every single example I have seen, takes at least twice as much effort to write, offering no significant advantage.

    If somebody needs a more sophisticated method for formatting strings, go ahead and create a new formatting library. But leave the true and tested way that has been working for nearly forty years alone. You cannot deprecate a basic functionality of a language just like that without dire consequences.

  • by Anonymous Coward on Wednesday May 12, 2010 @07:07PM (#32187722)
    Who is flaming C++ here? You are bringing up some imaginary adversaries which you then start to debate, like you are talking with the voices in your head. If you have some real comments to make, post a comment to someone else's post, and do not start a new thread.
  • by Capsaicin ( 412918 ) on Wednesday May 12, 2010 @10:52PM (#32189102)

    Why are you anthropomorphizing?

    Because it's a narrative device that can be used effectively to communicate. You didn't have any trouble understanding that "python" in that context stood for the python development community, did you? You didn't seriously think he was ascribing a human like intelligence to a language specification, did you? That anthropomorphism avoids clutter and actually increases readability, and after all, readability counts. :P

    That being said, I have to agree with you. Part of the strength of python surely is its general applicability so effectively fostered by the SIGs. I'm not even sure what OP means by "hard core" programming. That's what C is for, no?

    As far as switching over to float divisions by default, I thought that was meant to cut down on newbie bug reports ;) IOW, it's a little annoying to oldtimers (and the folks who regard integer division are the more natural) but probably obeys the principle of least surprise for most naive programmers out there.

How many NASA managers does it take to screw in a lightbulb? "That's a known problem... don't worry about it."