In this lesson, we will learn to change the color of the plots.

We'll cover the following

Different representations of color

In this lesson, we will learn about color. Matplotlib supports a variety of color definitions, which are listed below:

  • RGBA or RGB: RGBA is short for red, green, blue and alpha. In this format, you pass a tuple with 3 or 4 elements between 0 and 1, such as (0.1, 0.5, 1.0) or (0.1, 0.5, 1.0, 0.6).
  • hex: Hex RGB or RGBA string, such as #0F0F0F or #0F0F0F0F
  • single character: Uses a single letter, such as ‘r’ for red, or ‘b’ for blue. This is the most common color definition, and it is the one that we have used many times throughout the course.
  • color name: Uses the name of a color, such as red, blue, green.
  • Tableau Colors: One of {‘tab:blue’, ‘tab:orange’, ‘tab:green’, ‘tab:red’, ‘tab:purple’, ‘tab:brown’, ‘tab:pink’, ‘tab:gray’, ‘tab:olive’, ‘tab:cyan’}
  • float value in string: Set between 0 and 1, representing gray level, such as 0.7.

Below are examples of how to use the various color definitions we have discussed.

Get hands-on with 1200+ tech skills courses.