Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting many graphs with matplotlib

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

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

and select a pair from these at each iteration(for each graph). This is method only helps me when I have less than 22 graphs to draw. Any idea about making this more general with the coloring and the drawing-type?

like image 985
pacodelumberg Avatar asked Feb 23 '23 05:02

pacodelumberg


1 Answers

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 those you currently use:

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 you can create a full palette. Just adding light/dark versions of your current colors you are multiplying your possibilities.

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

like image 171
joaquin Avatar answered Mar 03 '23 20:03

joaquin