Thanks to theidioms.com

Bokeh Palettes for Color Mapping and Plotting in Python

Bokeh Palettes for Color Mapping and Plotting in Python
Data Science

Bokeh Palettes for Color Mapping and Plotting in Python

Bokeh Palettes for Color Mapping and Plotting in PythonBokeh Palettes for Color Mapping and Plotting in Python

Similar to how a painter uses a color palette to make a painting, a Bokeh palette is a collection of colors for color mapping in Python. Bokeh provides 5 different Bokeh Palettes for plotting in Python where each color palette has its own set of colors:

  1. Matplotlib Bokeh Palette
  2. D3 Bokeh Palette
  3. Brewer Bokeh Palette
  4. Color-Deficient Usability Bokeh Palette
  5. Large Bokeh Palette

Let us go over some of these color palettes one-by-one in this article and learn how to use the palettes.

1. Matplotlib Bokeh Palette

Bokeh includes the Matplotlib palettes called Magma, Inferno, Plasma, Viridis, and Cividis. Here is a visual aid to understand which palette provides which color map:

Matplotlib Bokeh Palette - Magma, Inferno, Plasma, Viridis, and Cividis

Using the Matplotlib Bokeh Palette is extremely simple and you only have to specify the color parameter in your plots as shown below:

# Importing Bokeh plotting and palettes modules
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import Magma, Inferno, Plasma, Viridis, Cividis
  
# File to save the model 
output_file("output.html") 
         
# Instantiating the figure object 
graph = figure(title = "Bokeh Palettes") 
  
# Demonstrating the Magma palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 
           top = [9] * 11,
           bottom = [8] * 11,
           width = 1,
           color = Magma[11])
  
# Demonstrating the Inferno palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 
           top = [7] * 11,
           bottom = [6] * 11,
           width = 1,
           color = Inferno[11])
  
# Demonstrating the Plasma palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 
           top = [5] * 11,
           bottom = [4] * 11,
           width = 1,
           color = Plasma[11])
  
# Demonstrating the Viridis palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 
           top = [3] * 11,
           bottom = [2] * 11,
           width = 1,
           color = Viridis[11])
  
# Demonstrating the Cividis palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 
           top = [1] * 11,
           width = 1,
           color = Cividis[11])
     
# Showing the model 
show(graph)
Matplotlib Bokeh Palette

D3 Bokeh Palette

Bokeh includes the categorical palettes from D3, which are shown below:

D3 Bokeh Palette

Using the D3 Bokeh Palette is extremely simple and you only have to specify the color parameter in your plots as shown below:

# Importing Bokeh plotting and palettes modules
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import Category10, Category20, Category20b, Category20c
  
# File to save the model 
output_file("output.html") 
         
# Instantiating the figure object 
graph = figure(title = "Bokeh Palettes") 
  
# Demonstrating the Category10 palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
           top = [9] * 10,
           bottom = [8] * 10,
           width = 1,
           color = Category10[10])
  
# Demonstrating the Category20 palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
           top = [7] * 10,
           bottom = [6] * 10,
           width = 1,
           color = Category20[10])
  
# Demonstrating the Category20b palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
           top = [5] * 10,
           bottom = [4] * 10,
           width = 1,
           color = Category20b[10])
  
# Demonstrating the Category20c palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
           top = [3] * 10,
           bottom = [2] * 10,
           width = 1,
           color = Category20c[10])
  
# Showing the model 
show(graph)
D3 Bokeh Palette

To learn about the rest of the color palette, you can refer to the official Bokeh.Palette documentation. The implementation method is same as displayed for the two palettes above.


Are you interested in working with data? Get a free trial month of LinkedIn Learning and learn Data Science and Machine Learning courses using Python, R, and SQL from top instructors.

Enroll in any one of the courses from the following fields today on LinkedIn Learning and start your free month of learning:

Disclaimer: When you subscribe to LinkedIn Learning, we may earn a small commission as an affiliate. We love the platform so much so that we have been using it ourselves at The Click Reader.

Bokeh Palettes for Color Mapping and Plotting in PythonBokeh Palettes for Color Mapping and Plotting in Python

Leave your thought here

Your email address will not be published. Required fields are marked *