Category Archives: Text

How-tos, software recommendations, code snippets, my opinion on stuff.

Subcategories: Energy, How-tos, LaTeX, Linux, Python

How to use TikZ for inline polygons

The trick is to define inner sep=0pt when beginning the tikzpicture environment, as I learned from pgf bug report #172 minimum size in regular polygon fails for small length from last year. Here is a minimum working example, adapted to my use case of inline polygon symbols with roughly text height, i.e. 2ex in my case:


\newcommand{\poly}[2]{\tikz[inner sep=0pt] {%
\node[regular polygon,%
regular polygon sides=#1,%
regular polygon rotate=#2,%
minimum size=2ex, fill] (0,0) {};}}

Triangle upwards \poly{3}{0}, 
triangle downward \poly{3}{180} 
and diamond \poly{4}{45}.

This snippet yields the following result:


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.

Random Dilbert bookmarklet

I’m addicted to the webcomic Dilbert by Scott Adams. He publishes one comic strip a day. With its archive ranging more than twenty years back, a random function to discover new old comics would be quite handy. That is what the following code snippet does: Create a random date between January 1st 1990 and today and navigate to that day’s comic address:

javascript:function pad(n){return n<10 ? '0'+n : n} var now =; var offset = (new Date(1990, 01, 01)).valueOf(); var rdate = new Date(offset + Math.round(Math.random() * (now-offset))); location.href = '' + rdate.getFullYear() + '-' + pad(rdate.getMonth()+1) + '-' + pad(rdate.getDate()) + '/';

Just copy the text and add it as the URL to a new bookmark called “Random Dilbert”. Whenever you click on it, it takes you to a different comic.

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


AQUA-CSP is one of three conceptual studies which explored different parts of the DESERTEC project, a concept which relies on solar power from the world’s desserts as a major energy source for Europe. In previous posts I already talked about the two other studies MED-CSP andTRANS-CSP, the first focused on generation, the second on transportation of the generated electricity. This article deals with the third, often overlooked, aspect if this undertaking: desalination of huge quantities of sea water. Continue reading

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