Wisent: a Python parser generator. A Python LR(1) parser generator. … read more

Blog: Parsing Apache Log Files with Python. How to process web server log files in Python? … read more

Blog: Time zone aware timestamps in JavaScript and Python. A short tutorial on computing timestamps in JavaScript and Python. … read more

figures with matplotlib

By , on [atom feed]

I like to use the matplotlib Python library to create figures for use in my articles. Unfortunately, the matplotlib default settings seem to be optimised for screen-viewing, so creating pictures for inclusion in a scientific paper needs some fiddling. Here is an example script which sets up things for such a figure.

#! /usr/bin/env python

import matplotlib
matplotlib.use("PS")
from pylab import *

rc("font", family="serif")
rc("font", size=10)

width = 4.5
height = 1.4
rc("figure.subplot", left=(22/72.27)/width)
rc("figure.subplot", right=(width-10/72.27)/width)
rc("figure.subplot", bottom=(14/72.27)/height)
rc("figure.subplot", top=(height-7/72.27)/height)
figure(figsize=(width, height))

x = loadtxt("x.dat")
plot(x[:,0], x[:,1], "k-")

savefig("figure.eps")

The script performs the following steps:

This is an excerpt from Jochen's blog.
Newer entry: New Book Chapter
Older entry: CO2 emissions for different modes of transportation (updated)

Copyright © 2009, Jochen Voss. All content on this website (including text, pictures, and any other original works), unless otherwise noted, is licensed under a Creative Commons Attribution-Share Alike 3.0 License.