I’ve recently been polishing a number of graphs to get them up to publication quality (coming soon!), and one of the necessary customisations that came up was the style of dashed/dotted lines. Matplotlib’s default dotted and dash/dotted line styles aren’t very clear in a lot of plots, and can be difficult to distinguish (e.g. the dash/dotted style looks too much like dots).
Happily, you can make your own custom line styles, using a sequence (list) of numbers and the set_dashes() method of the Line2D object. To do this:
import pylab as P P.subplot(111) line = P.plot(x, y) # 'line' is actually a list of lines. We want line seq = [2, 4, 7, 4] line.set_dashes(seq)
Here, seq is the alternating sequence of dashes and spaces. seq draws a line of length 2, seq draws a space (i.e. no line) of length 4, seq a line of length 7, and seq a space of length 4.
You can carry on this sequence indefinitely if you like; even indices are drawn as lines, odd indices as spaces. For example, seq = [2, 2] would look like dots, and seq = [7, 4, 3, 4] is a clearer dash-dotted line than the default. You can even use float lengths for the dashes, rather than integers.
(There’s a rather spartan example on the matplotlib website too.)