How to change the default matplotlib font

The default fonts for matplotlib are set in file matplotlibrc in the folder $USER_HOME/.matplotlib. You can find them here, depending on your operating system:

  • Windows: C:\Users\YourName\.matplotlib\matplotlibrc
  • Linux: /home/YourName/.matplotlib/matplotlibrc

Within the file, search for the font section, and uncomment (remove the hash symbol # at beginning of line) or add the following settings as desired. In the shown example, I set Arial as the default:         : sans-serif          : normal
#font.variant        : normal
#font.weight         : medium
#font.stretch        : normal

# ...

#font.serif          : Times New Roman, ...
font.sans-serif     : Arial, ...
#font.cursive        : ... cursive
#font.fantasy        : ... fantasy
#font.monospace      : ... monospace

Upon the next start of the Python interpreter, your plots should be labelled with the new font.

Further reading

How to autoreload packages while using them in IPython

I use IPython to interactively use and debug code that I edit in a text editor at the same time. Unfortunately, Python does not automatically reload packages and functions after an initial import foo, simply for performance reasons.

Fortunately, there is a solution: the IPython extension autoreload does what its name says: either all (how I use it) or only selected (imported using magic function %aimport) are refreshed, whenever I hit the Enter key. Here’s a short how-i-use-it demo, involving a minimal package foo with a helloworld function bar:

In [1]: %load_ext autoreload
In [2]: %autoreload 2
In [3]: import foo
In [4]:
Hello World!

In [5]: !cat
def bar():
    print('Hello World!\n')

In [6]: # edit in editor
In [7]: !cat
def bar():
    print('Hello me!\n')

In [8]: # bar() is automagically reloaded
In [9]:
Hello me!

How do you get it? It’s already bundled with IPython by default! Happy hacking!

How to use custom colours in LaTeX

I will post short minimum working examples (MWEs) of minimal LaTeX documents, showing a certain feature in action. Though the well-maintained LaTeX Wikibook is a much more extensive resource than a collection of such examples could ever be, they show directly compilable examples compared to isolated snippets.

I start simple: custom text colours, using different colour models. Shown here are RGB (0-255) and HTML (00-FF) style definitions. The text shows two different ways to access them. Bonus: these colours can be used in TikZ as well.


\definecolor{cool}{RGB}{0, 110, 220}
\definecolor{heat}{RGB}{240, 120, 40}
I am some \textcolor{heat}{really hot}, 
though \textcolor{cool}{also cold} text.
{\color{pink}Bright colors} are discouraged.

Stikked – a self-hosted open source alternative to Pastebin


Ever wanted to share or loosely collaborate on a document, but did not feel save enough to put it on a public text hosting service like Pastebin?

Thanks to Ben McRedmond and Claude Hole, there is Stikked. It is a small text pasting script. It needs a webserver with PHP 5 and a MySQL database. Installation is manual, but easy and well documented. Continue reading “Stikked – a self-hosted open source alternative to Pastebin”

How to convert video to MPEG 422 HD format for import in Lightworks Free

The best freely available video editing software for Windows is Lightworks (version 11.0.1). While it is free (as in beer), it has very restricted selection of import video formats at the moment. My camera (Canon EOS D550) delivers H.264 encoded MOV files, which—without other software—would require a 50 €/year codec license if you want to import them directly. Fortunately, I found a way to import my videos… Continue reading “How to convert video to MPEG 422 HD format for import in Lightworks Free”

Optimise nonlinear functions using Matlab or Octave

Contour plot of a test function. In the middle its minimum is shown. White triangles are spread throughout the picture, denoting the locations of the initial simplices.

For my diploma thesis I needed an easy-to-use optimisation algorithm which could minimise a given function. I had access to Matlab, but surprisingly, none of the supplied optimisation functions seemed to satisfy my needs: I wanted to globally minimise a non-linear function within boundaries without using gradients.

So I did a little research and found a Globalized Nelder-Mead method (PDF), which is a tuned version of the good old downhill simplex algorithm. Then I implemented it as a Matlab function. By the way: the function also works fine with Octave. Continue reading “Optimise nonlinear functions using Matlab or Octave”

Mathematical Formulas in Microsoft Word

Formula typesetting can be a tedious work in most typewriter software. Word (here: Version 2003) is no excuse. When you are — like me — forced to use this software for writing technical reports containing formulas, then this tip might be useful for you. The “typical” way of writing formulas is creating formula objects which can be edited by a double click on them. However, as soon as a document contains many of those objects, their handling becomes uncomfortable because they don’t behave like their surrounding text.

But there is another, almost perfectly hidden feature which allows to typeset easy formulas as real text which respects text formatting styles: Equation fields. Continue reading “Mathematical Formulas in Microsoft Word”

How to use custom-made Themes under Windows XP/Vista/7

Deskmodding is the art or the act of customizing the appearance of the graphical user interface. Usually this is done on the level of the operating system, but there are also single applications that allow to modify their appearance by so-called skins. For the operating system Windows it is not possible to easily change the default appearance as the selection of themes that can be selected is limited to a handful of designs like the classic Windows interface, Luna for Windows XP and Aero since Vista. Windows Media Center Edition brought a revamped version of Luna which became very popular.

But apart from those designs, Windows does not permit to select user-made themes. This is due to a check in the file uxtheme.dll in the system32 folder. There are dozens of downloads of patches that promise to replace the file with a patched version that permits so select whatever style one prefers. But it is easy to download the wrong patch or even get a virus on one’s computer this way. But there is an alternative: UxStyle. Continue reading “How to use custom-made Themes under Windows XP/Vista/7”

Using Funambol to sync Thunderbird(s) and Windows Mobile phone

This is an article explaining how to synchronise one calendar (+tasks) and one address book of two PCs with Thunderbird (Lightning plugin for calendar) and a Windows Mobile phone. It is based on the open source synchronisation server Funambol and needs one of the computers to act as a server. The advantage to other solutions I tried (like FinchSync or the Addressbooks Synchroniser add-on) is that it covers all synchronisations even between different device types.

One disadvantage of my how-to is that the data which is synchronised is transmitted without encryption. However, it is possible to somehow use SSL encryption for the data transfer, but so far I am afraid of the effort to reconfigure all again now that it works. Another disadvantage concerns the fact that currently only one calendar and one address book can be synchronised. While this restriction does not bother me now, it might render this solution useless for you. Continue reading “Using Funambol to sync Thunderbird(s) and Windows Mobile phone”