{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Specifying Colors\n\nMatplotlib recognizes the following formats to specify a color.\n\n+--------------------------------------+--------------------------------------+\n| Format | Example |\n+======================================+======================================+\n| RGB or RGBA (red, green, blue, alpha)| - ``(0.1, 0.2, 0.5)`` |\n| tuple of float values in a closed | - ``(0.1, 0.2, 0.5, 0.3)`` |\n| interval [0, 1]. | |\n+--------------------------------------+--------------------------------------+\n| Case-insensitive hex RGB or RGBA | - ``'#0f0f0f'`` |\n| string. | - ``'#0f0f0f80'`` |\n+--------------------------------------+--------------------------------------+\n| Case-insensitive RGB or RGBA string | - ``'#abc'`` as ``'#aabbcc'`` |\n| equivalent hex shorthand of | - ``'#fb1'`` as ``'#ffbb11'`` |\n| duplicated characters. | |\n+--------------------------------------+--------------------------------------+\n| String representation of float value | - ``'0'`` as black |\n| in closed interval ``[0, 1]`` for | - ``'1'`` as white |\n| grayscale values. | - ``'0.8'`` as light gray |\n+--------------------------------------+--------------------------------------+\n| Single character shorthand notation | - ``'b'`` as blue |\n| for some basic colors. | - ``'g'`` as green |\n| | - ``'r'`` as red |\n| .. note:: | - ``'c'`` as cyan |\n| The colors green, cyan, magenta, | - ``'m'`` as magenta |\n| and yellow do not coincide with | - ``'y'`` as yellow |\n| X11/CSS4 colors. Their particular | - ``'k'`` as black |\n| shades were chosen for better | - ``'w'`` as white |\n| visibility of colored lines | |\n| against typical backgrounds. | |\n+--------------------------------------+--------------------------------------+\n| Case-insensitive X11/CSS4 color name | - ``'aquamarine'`` |\n| with no spaces. | - ``'mediumseagreen'`` |\n+--------------------------------------+--------------------------------------+\n| Case-insensitive color name from | - ``'xkcd:sky blue'`` |\n| `xkcd color survey`_ with ``'xkcd:'``| - ``'xkcd:eggshell'`` |\n| prefix. | |\n+--------------------------------------+--------------------------------------+\n| Case-insensitive Tableau Colors from | - ``'tab:blue'`` |\n| 'T10' categorical palette. | - ``'tab:orange'`` |\n| | - ``'tab:green'`` |\n| | - ``'tab:red'`` |\n| | - ``'tab:purple'`` |\n| .. note:: This is the default color | - ``'tab:brown'`` |\n| cycle. | - ``'tab:pink'`` |\n| | - ``'tab:gray'`` |\n| | - ``'tab:olive'`` |\n| | - ``'tab:cyan'`` |\n+--------------------------------------+--------------------------------------+\n| \"CN\" color spec where ``'C'`` | - ``'C0'`` |\n| precedes a number acting as an index | - ``'C1'`` |\n| into the default property cycle. +--------------------------------------+\n| | :rc:`axes.prop_cycle` |\n| .. note:: Matplotlib indexes color | |\n| at draw time and defaults | |\n| to black if cycle does not | |\n| include color. | |\n+--------------------------------------+--------------------------------------+\n\n\n.. seealso::\n\n The following links provide more information on colors in Matplotlib.\n * :doc:`/gallery/color/color_demo` Example\n * `matplotlib.colors` API\n * :doc:`/gallery/color/named_colors` Example\n\n\"Red\", \"Green\", and \"Blue\" are the intensities of those colors. In combination,\nthey represent the colorspace.\n\nMatplotlib draws Artists based on the ``zorder`` parameter. If there are no\nspecified values, Matplotlib defaults to the order of the Artists added to the\nAxes.\n\nThe alpha for an Artist controls opacity. It indicates how the RGB color of the\nnew Artist combines with RGB colors already on the Axes.\n\nThe two Artists combine with alpha compositing. Matplotlib uses the equation\nbelow to compute the result of blending a new Artist.\n\n::\n\n RGB_{new} = RGB_{below} * (1 - \\alpha) + RGB_{artist} * \\alpha\n\nAlpha of 1 indicates the new Artist completely covers the previous color.\nAlpha of 0 for top color is not visible; however, it contributes to blending\nfor intermediate values as the cumulative result of all previous Artists. The\nfollowing table contains examples.\n\n+---------------+-------------------------------------------------------------+\n| Alpha value | Visual |\n+===============+=============================================================+\n| ``0.3`` | .. image:: ../../_static/color_zorder_A.png |\n+---------------+-------------------------------------------------------------+\n| ``1`` | .. image:: ../../_static/color_zorder_B.png |\n+---------------+-------------------------------------------------------------+\n\n
Re-ordering Artists is not commutative in Matplotlib.