How can I automatically change matplotlib line markers?

Possible duplicate:
Can I iterate over line styles in matplotlib
matplotlib - black and white color palette (with dashes, dots, etc.)

I use matplotlib (python) and I draw multiple lines on the same plot.

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

I know that I can make a list of different types of lines and use them, but this includes capturing all types of lines and adding them to each script. I want to build some lines. I suppose there should be an automatic path.

+4
source share
1 answer

I do not think it is possible that you automatically want, but it is certainly doable with very little effort. The way I do it on my stories, I do all the ideas that I want, and then change the markers. However, in my experience, finding the right marker cycle depends on the graph you want to display, and the graph is displayed in context. I would truly recommend that you choose this manual selection of markers and find out what looks best on your charts. After a small sketch showing how I am doing this (but you 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() 
+7
source

Source: https://habr.com/ru/post/1399326/


All Articles