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.