make plot() cycle through line style instead of colour

Dear list,

if I do a

plot([1,2],[1,2])
plot([1,2],[1,3])
plot([1,2],[1,4])

I will get three lines. All have linestyle='-', the colour is changed
automatically: blue, green, red, ...

Can I change this behaviour to: All have the colour black, and the
linestyle is changed /automatically/ '-', '--', '-.', ...?

Thanks in advance,
Sebastian.

You can use itertools.cycle, that will repeatedly loop over a sequence of items:

import matplotlib.pyplot as pl
from itertools import cycle
styles = cycle(['k-', 'k--', 'k-.'])
plot([1,2], [1,2], styles.next())
plot([1,2], [1,3], styles.next())
plot([1,2], [1,4], styles.next())

Ryan

ยทยทยท

On Tue, Feb 15, 2011 at 9:24 AM, Sebastian Busch <webmaster@...2599...> wrote:

Dear list,

if I do a

plot([1,2],[1,2])
plot([1,2],[1,3])
plot([1,2],[1,4])

I will get three lines. All have linestyle='-', the colour is changed
automatically: blue, green, red, ...

Can I change this behaviour to: All have the colour black, and the
linestyle is changed /automatically/ '-', '--', '-.', ...?

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma