Charles Brunet Charles Brunet - 8 months ago 40
Python Question

Can i cycle through line styles in matplotlib

I know how to cycle through a list of colors in matplotlib. But is it possible to do something similar with line styles (plain, dotted, dashed, etc.)? I'd need to do that so my graphs would be easier to read when printed. Any suggestions how to do that?


Something like this might do the trick:

import matplotlib.pyplot as plt
from itertools import cycle
lines = ["-","--","-.",":"]
linecycler = cycle(lines)
for i in range(10):
    x = range(i,i+10)

Result: enter image description here