Getting started: the basic bits of kit

•March 6, 2011 • Leave a Comment

This guide should give you a good overview of the packages you’ll need to download and install to start scientific programming using Python.

First, Python itself.  There are later versions than the 2.6 which I use but:

a) they can have some compatibility issues when installing other toolkits

b) unless you really know what you’re doing, 2.6 is capable of basically everything you’ll ever want to do.

So, here it is:

You’ll also need the numerical extensions to python, NumPy (which lets you use arrays and matrices) and SciPy (which has lots of useful functions for integration, linear algebra, Fourier analysis and so on).

Luckily there are ready-made installers of both of these for both mac and windows:

Those for NumPy can be found here at
(For direct download of the 2.6 compatible version, you can use this link for mac or this one for windows)
And SciPy is here (Or you can use the direct downloads of the 2.6 compatible version  for a mac or for windows)
If you want to do any plotting or visualisations you’ll need Matplotlib too. It’s very similar to matlab in its syntax and an overall delight to use. Find it here (Or directly download the 2.6 compatible version for windows and mac ).
NetworkX is another handy plugin for dealing with everything to do with networks. The easiest possible way to set it up is with another piece of software called easy install (documentation of which can be found here). I have a feeling (don’t quote me) that this comes pre-loaded on the mac,  but for windows, you can access the download page here or just download it directly.
Once that’s done, open up a terminal window (start>run>”cmd” for windows) and use the command “easy_install networkx”. ‘Tis as simple as that.
Since my work is in a global dynamics project, I often have to produce plots overlaid on maps. For that matplotlib has a handy little toolbox called Basemap. The sourceforge page includes a lovely windows installer, unfortunately though, there’s no such thing for mac users. I have managed to set up basemap on my mac, but cannot for the life of me remember how. I know it took a long time to work it out, and I know I used this guide, which was about as useful as a chocolate teapot, but other than that you’re on your own I’m afraid.

Just another Python blog.

•March 4, 2011 • Leave a Comment

I’m Hannah Fry, I’ve been lecturing at UCL for 5 years, trained as a mathematician and now working as a fully fledged academic on a global dynamics and complexity project.

Now that I’ve finished my PhD, I thought it was time to grow up and learn a proper  programming language. Python, in its similarities to matlab and easy-read syntax seemed a pretty friendly place to start.

I’ve done a fair amount  of programming before and know how to structure a for loop, but any time I ran into trouble I’ve found it a real headache to find the answers to my problems.

The python forums (like stackoverflow) can be useful, but more often than not it’s an absolute blummin’ nightmare trying to decipher the experts replies. Plus, you have to occasionally deal with users using handles like ‘ICanHazSeks’ (who lets face it, probably cannot)  writing things like “I really fail to see how that error message is hard to understand”.

All I want is a clear answer to a clear question. For example,

“When using matplotlib, how do you change the textsize of the numbers (or ticks) along an axis?”


You have to loop through each individual label.

If ‘ax’ is your axis handle, and ‘size’ the desired textsize, you can use (one for each axis):

[tick.label1.set_fontsize(size) for tick in ax.xaxis.get_major_ticks()]

[tick.label1.set_fontsize(size) for tick in ax.yaxis.get_major_ticks()]

It took me 2 hours of googling to work that out.

So that’s what this blog is for, a record of all the difficulties I’ve encountered in learning how to write in python, and a library of my (admittedly inelegant) solutions.