Setting colors in Matplotlib
Many elements in a Matplotlib figure can have their colors specified. There are several ways to do so. You will come across the color
parameter as a keyword argument for style settings very often in different functions. The alternate abbreviated keyword c
can often be used. We will first briefly introduce the general rule here.
Single letters for basic built-in colors
There is a list of common colors we can quickly call with single letters:
b
: Blueg
: Greenr
: Redc
: Cyanm
: Magentay
: Yellowk
: Blackw
: White
Names of standard HTML colors
Examples are coral
, gold
, springgreen
, deepskyblue
, and blueviolet
. You can find the full list here: https://matplotlib.org/examples/color/named_colors.html.
RGB or RGBA color code
You can parse a tuple of three to four float numbers in the range of 0-1, such as (0.2,0.4,0.8)
or (0.2,0.2,0.3,0.8)
. The first three numbers are RGB values that define the amount of red, green, and blue light to mix in the color. The optional fourth number is...