Tags

, , ,

I’m sure many of my fellow scientists spend a relatively large chunk of their time making plots, graphs, and figures of one sort or another.  There are a plethora of cool tools out there for doing this, from proprietary tools like Mathematica or IDL to free software kits like GNUplot.  While GNUplot is useful and handy (and IDL is powerful and expensive), I’m a python guy primarily, so I like my tools to interface well with my existing code, and has a more pythonic interface.  For this, I turn to matplotlib, a powerful suite for generating all sorts of plots from python.

Why Matplotlib?

I already explained why, fool!  Actually, I need to be able to whip together quick plots all the time as a part of my research, and when it comes to rapid prototyping, python is, IMHO, the absolute best language out there.  So, having a nice python module for doing plots lets me whip up quick test figures to examine in a few minutes for even rather complex tasks.

Getting Matplotlib

If you are already running one of the common Linux distributions, matplotlib is a simple apt-get or yum install away.  Under Debian or Ubuntu, simply type:

sudo apt-get install python-matplotlib

With Fedora, just use:

sudo yum install python-matplotlib

If you are running on a Linux distro that lacks a package manager, or are running on another OS, check out the matplotlib installation guide here. Once you have that finished, I’d also recommend (if you don’t already have them) getting numpy and scipy, as these tools will be very handy for actually generating data worth plotting.

To check that the installation was successful, simply fire up a terminal with python, and type:

import matplotlib

If you don’t get any error messages, hooray! You are good to go. I’ll be updating this series later this week with a simple introduction to plotting lines and points on an X-Y axis.

Basic Data Plotting With Matplotlib

Part 2: Lines & Points

Part 3: Histograms

Part 4: Multiple Plots (Coming Soon)

Part 5: ?