Matplotlib For Python Developers
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 amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
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 amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
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.
Blasphemy is a human right. Blasphemophobia kills.
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.
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.
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.
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
2
>>> from __future__ import division
>>> 5/2 #Things work differently in the future
2.5
>>> 5//2 #You can use a double '/' to explicitly force an integer in Python 3
2