Please create an account to participate in the Slashdot moderation system


Forgot your password?
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×

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 0100010001010011 ( 652467 ) on Wednesday May 12, 2010 @03:32PM (#32185622)

    Wake me when there is something even close to replace Simulink. Matlab is cool and all, but the real power of the program is Simulink.

  • by xiox ( 66483 ) on Wednesday May 12, 2010 @04:29PM (#32186328) Homepage

    If you find matplotlib hard, try my Veusz [] python plotting package. It has a GUI you can build plots within. It is scriptable in python, and even the saved file format is a python script to generate the plot. It can read a variety of data formats.

  • by Anonymous Coward on Wednesday May 12, 2010 @04:38PM (#32186440)
    At one point I was trying to decide which graphics plotting library I wanted to get proficient with. I considered mathplotlib but I eventually decided on R + ggplot [] and am very satisfied. Some examples here []. True, I was doing mainly statistical stuff so the R connection wasn't a liability. But I like the philosophy of ggplot: the "gg" stands for "grammar of graphics". The library doesn't demand that you adjust every little thing separately to make interesting graphs; it gives you a variety of concepts (in ggplot parlance, geoms, layers, statistics, scales, etc.) and lets you combine them in arbitrary ways. It takes some getting used to but you end up being able to make great graphs without much twiddling with the details.
  • by Anonymous Coward on Thursday May 13, 2010 @12:58AM (#32189658)

    For me, gnuplot is the best plotting program out there. It's very easy to use from python using ( It essentially starts a gnuplot session that sends it commands through a pipe. You can choose if data is sent through a FIFO or temporary files (slower, but required for some of the interactive plotting features).

    In a nutshell:

    import Gnuplot as gp

    Conversion of most sensible python data types is done on the fly:
    g.plot( [(x,x**2) for x in range(-5,5)] )

    Plus, g.interact() will just drop you into the currently running gnuplot session, which can be very convenient.

  • by brunos ( 629303 ) on Thursday May 13, 2010 @02:25AM (#32189950)
    Hi, I see your point: Python is getting a lot better for scientific use, maybe not so much due to the changes in 3.0 but rather because the community has grown (e.g. Python(x,y), Enthought). There are a few things that make Python what I use most of the time for scientific work: - The language is better thought out i.e. the Matlab tradition of having one function per file is just annoying. - The quality of the old Fortran algorithms which scipy wraps is consistently better than that of Matlab functions e.g. Matlab fitting routines are a mess, I get much more accurate results with scipy. - Compatibility between versions: matlab code from my colleagues always needs some work to run: either because there have been some changes between matlab versions, or they use a function from a toolbox that I don't have, even though there is an equivalent one in standard matlab. Since we changed to Python all is fine. - When you cannot vectorize a small piece of code, scipy offers a few ways in which compiled code can be added transparently: cython, pyrex, f2py and even pycuda. Much easier than .mex in matlab. - Python has a large set of very useful libraries for doing scientific work e.g. networkx, vpython ... - Thanks to Python's large set of other libraries, it is trivial to do things such as parsing complex files, interfacing with lab equipment (pyvisa, ...) interfacing with the windows/linux/mac GUIs, using databases, sending data over the network etc. All these things are really handy in the lab. - I don't mind paying for software, but the license management is really a problem: It has happened quite a few times, that Matlab has stopped working because something in the license management had changed. Loosing a day of work of a research group is expensive. - Of course, the fact that students can just install Python for free, and maybe use it in their future non-scientific job is a plus.
  • by Vireo ( 190514 ) on Thursday May 13, 2010 @08:51AM (#32191946)

    Speed in interpreted languages such as Python and Matlab depends strongly on what it is doing exactly, and how it is done. For example, both Matlab and the numpy Python module use external, pre-compiled, and highly optimized basic linear algebra subroutines (BLAS) for things like matrix multiplication. Matlab ships with several different BLAS, but it's even possible for Matlab to use the ATLAS BLAS which numpy uses.

    So the speed would be the same in that case, assuming both your Matlab installation and numpy are configured to use the same number of processors (linear algebra is typically highly parallel, and in huge matrix operations, multi-thread overhead will be negligible).

    If you code your own matrix multiplication naively in C, you may end up with a factor of 6 or 7 in speed *below* that of Matlab.

    However if we're talking about generic loops for example, C is then much, much faster. Matlab has a Just-in-Time (JIT) optimizer which vectorizes straightforward loops; the same for Python is not ready yet (this would be the Unladen Swallow project from Google I think). Depending on the precise morphology of a loop, very different speeds would be obtained in Matlab, C or Python. The lesson here is to use numpy or scipy precompiled and pre-optimized code whenever this is possible. But when it's done right, there's generally much less difference between Matlab, Python and optimized C than many people think.

  • by Vireo ( 190514 ) on Thursday May 13, 2010 @09:03AM (#32192062)

    A few quick comments on this well-informed post...

    Price: you're right here, Matlab is expensive and is locking you down, but at least you get very decent support from The MathWorks.

    Graphics: Matlab has a huge library of very usable graphics functions. However it is nonetheless lacking in certain areas. GUIs is one of them (you can only embed Matlab graphics in a Matlab GUI, and the various methods to build a GUI in Matlab mostly sucks compared to what is possible outside of Matlab). Also, while Matlab figures exported to other format (PDF, EPS, bitmaps) are fine, on-screen Matlab figures are not anti-aliased and sometimes present quirks that are not really there. Matplotlib uses the Antigrain library for screen output, so the end result is much more pleasing to the eye.

    Speed: Using numpy, you benefit from the binary linear algebra subroutine (BLAS) speed, much as Matlab. Generic loops tends to be slower than Matlab because of Matlab's Just-in-Time (JIT) optimizer.

    Documentation: I'll give you this one hands-down: Matlab has *excellent* documentation, written by experts in the field. This is an often neglected area, but clean and profuse documentation and examples allows you to do more things, much quicker.

    Dev environment: very good in Matlab, but using any Python syntax-aware text editor + the IPython shell, I don't miss much when developing Python. Python is generally more consistent (e.g. you can define a multi-statement function interactively in the Python shell), which speeds up development. Also, Matlab is beginning to feel a namespace crunch. All functions in all toolboxes are in the same namespace in Matlab, and it's beginning hard to find creative new names for my own function, all the most if they replicate some Matlab's built-in capability. Python's namespace / module imports solves this problem very nicely.

Old programmers never die, they just branch to a new address.