Tuesday 6 July 2010

Python Matplotlib: Using Scientific Number Format on Axes

This post will help you with formatting the numbers on axes of your graphs, if you are using Python Matplotlib. When the data you are plotting exceeds a pre-defined value range, Matplotlib will automatically switch to using scientific number formatting.

However, sometimes this can happen a bit erratic or you might want to always use scientific notation (which might be good practice in most cases anyways). This can be done via the following set of commands:

yfm = axScatter.yaxis.get_major_formatter()
yfm.set_powerlimits([ -3, 3])

In order to use these command, matplotlib needs to be included, of course. For plotting examples in Python please refer to the Matplotlib Example Gallery.

Ubuntu Linux: Which Version am I Running?

If you are running Linux on your machine, in particular Ubuntu, it can be tedious if you just quickly want to find out the version of the Kernel you are running and which Ubuntu release you are running (including it's nickname/codename!).

So here are two quick ways of getting the information from the command line:

lsb_release -a

... will give you a good idea of which version you are running, e.g.:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic

... and if you want to find out more about the kernel version, this can be done via typing

uname -a