Building a lot of charts with matplotlib

Whenever I want to plot multiple 2d line graph plots with matplotlib, I define two lists:

coloTypesList=["b","g","r","c","m","y","k"]; drawTypesList=["-","--","x"];

and select a pair of them at each iteration (for each graph). This method helps me when I have less than 22 schedules. Any idea to make this more general with coloring and drawing?

+4
source share
1 answer

From the lists you give, you have 21 combinations:

 >>> from itertools import product >>> markers = ["-", "--", "x"] >>> colors = ["b", "g", "r", "c", "m", "y", "k"] >>> [a + b for a, b in product(colors, markers)] ['b-', 'b--', 'bx', 'g-', 'g--', 'gx', 'r-', 'r--', 'rx', 'c-', 'c--', 'cx', 'm-', 'm--', 'mx', 'y-', 'y--', 'yx', 'k-', 'k--', 'kx'] 

However, there are many more options than the ones you are currently using:

Line style or marker:

 ================ =============================== character description ================ =============================== ``'-'`` solid line style ``'--'`` dashed line style ``'-.'`` dash-dot line style ``':'`` dotted line style ``'.'`` point marker ``','`` pixel marker ``'o'`` circle marker ``'v'`` triangle_down marker ``'^'`` triangle_up marker ``'<'`` triangle_left marker ``'>'`` triangle_right marker ``'1'`` tri_down marker ``'2'`` tri_up marker ``'3'`` tri_left marker ``'4'`` tri_right marker ``'s'`` square marker ``'p'`` pentagon marker ``'*'`` star marker ``'h'`` hexagon1 marker ``'H'`` hexagon2 marker ``'+'`` plus marker ``'x'`` x marker ``'D'`` diamond marker ``'d'`` thin_diamond marker ``'|'`` vline marker ``'_'`` hline marker ================ =============================== 

Color abbreviations:

 ========== ======== character color ========== ======== 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' black 'w' white ========== ======== 

Note that you can specify colors as RGB or RGBA tuples ( (0, 1, 0, 1) ) so that you can create a complete palette. By simply adding light / dark versions of your current colors, you multiply your possibilities.

I'm not sure that you need so many combinations of markers and colors in one plot. Given that you use only standard colors, you have a maximum of 26 * 8 = 208 combinations (well, white should not be taken into account ...).

+8
source

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


All Articles