Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I have matplotlib change line markers automatically? [duplicate]

Possible Duplicate:
Can i cycle through line styles in matplotlib
matplotlib - black & white colormap (with dashes, dots etc)

I'm using matplotlib (python) and I am plotting several lines on a single plot.

By default, python is assigning a different color to each line, but I want it to assign different line types and just use black for all of them.

I know I could make a list of different line types and use them, but that involves grabbing all the line types and adding them to each script I want to plot multiple lines with. I figure there has to be an automatic way.

like image 829
pocketfullofcheese Avatar asked Mar 02 '12 06:03

pocketfullofcheese


1 Answers

I don't think that is possible that automatically you would want, but it is certainly doable with a very little effort. The way I do in my plots, I do all the plotting I want, then I change the markers. However, in my experience finding a right marker cycle depends on the graph you want to show and on the context the graph appears. I would verily encourage you to opt for this manual selection of markers and find out what looks the best on your graphs. Following a little sketch showing the way I do (but you've already mentioned something similar in your question):

import matplotlib.pyplot as plt

f = plt.figure(1); f.clf()
ax = f.add_subplot(111)
ax.plot([1,2,3,4,5])
ax.plot([5,4,3,2,1])
ax.plot([2,3,2,3,2])

import itertools
for l, ms in zip(ax.lines, itertools.cycle('>^+*')):
    l.set_marker(ms)
    l.set_color('black')

plt.show()
like image 145
dawe Avatar answered Sep 27 '22 17:09

dawe