用matplotlib绘制许多图

时间:2011-12-04 16:59:54

标签: python plot matplotlib

每当我想用matplotlib绘制多个2d折线图时,我定义了两个列表:

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

并在每次迭代时从这些中选择一对(对于每个图)。当我绘制的图形少于22个时,这种方法只能帮助我。有关使用着色和绘图类型使其更通用的任何想法吗?

1 个答案:

答案 0 :(得分:8)

从您给出的列表中,您有21种组合:

>>> 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']

但是,目前使用的选项还有很多选择:

线型或标记:

================    ===============================
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
================    ===============================

颜色缩写:

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

请注意,您可以将颜色指定为RGB或RGBA元组((0, 1, 0, 1)),以便创建完整的调色板。只需添加当前颜色的浅色/深色版本,就可以增加您的可能性。

我不确定在一个唯一的情节中你需要这么多的标记和颜色组合。鉴于您只使用标准颜色,您最多可以使用26 * 8 = 208种组合(嗯,白色不应该被考虑在内......)。