Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Bokeh
  • Matplotlib
  • Pandas
  • Seaborn
  • Ggplot
  • Plotly
  • Altair
  • Networkx
  • Machine Learning Math
  • Machin Learning
  • Data Analysis
  • Deep Learning
  • Deep Learning Projects
  • NLP
  • Computer vision
  • Data science
  • Machin Learning Interview question
  • Deep learning interview question
Open In App
Next Article:
How to add color-picker in Bokeh?
Next article icon

How to use Color Palettes in Python-Bokeh?

Last Updated : 28 Jul, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh provides us with multiple color palettes in the bokeh.palettes module. Let us see how to use these color palettes in Bokeh.

A palette is a simple plain Python list of (hex) RGB color strings. For example, the blues8 palette has the colors : ('#084594', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#deebf7', '#f7fbff').

There are 5 types of built-in color palettes in Bokeh :

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

Matplotlib Palettes

Bokeh provides us with Matplotlib color palettes. There are 5 types of Matplotlib color palettes :

  • Magma
  • Inferno
  • Plasma
  • Viridis
  • Cividis

Each type of color palette has 10 different versions of the palette with varying number of colors, which are 3, 4, 5, 6, 7, 8, 9, 10, 11 and 256.

Example : We will be demonstrating the Matplotlib palettes by plotting multiple vertical bars using the vbar() function.




# importing the 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("gfg.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])
     
# displaying the model 
show(graph)
 
 

Output :

D3 Palettes

Bokeh provides us with D3 categorical color palettes. There are 4 types of D3 color palettes available :

  • Category10
  • Category20
  • Category20b
  • Category20c

Example : We will be demonstrating the D3 palettes by plotting multiple vertical bars using the vbar() function.




# importing the modules 
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import Category10, Category20, Category20b, Category20c
  
# file to save the model 
output_file("gfg.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])
  
# displaying the model 
show(graph)
 
 

Output :

Brewer Palettes

Bokeh provides us with ColorBrewer palettes. There are 35 types of ColorBrewer palettes available :

  • Accent
  • Blues
  • BrBG
  • BuGn
  • BuPu
  • Dark2
  • GnBu
  • Greens
  • Greys
  • OrRd
  • Oranges
  • PRGn
  • Paired
  • Pastel1
  • Pastel2
  • PiYG
  • PuBu
  • PuBuGn
  • PuOr
  • PuRd
  • Purples
  • RdBu
  • RdGy
  • RdPu
  • RdYlBu
  • RdYlGn
  • Reds
  • Set1
  • Set2
  • Set3
  • Spectral
  • YlGn
  • YlGnBu
  • YlOrBr
  • YlOrRd

Example : We will be demonstrating the ColorBrewer palettes by plotting multiple vertical bars using the vbar() function.




# importing the modules 
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import BrBG, PiYG, RdGy, RdYlGn, YlGnBu
  
# file to save the model 
output_file("gfg.html") 
         
# instantiating the figure object 
graph = figure(title = "Bokeh Palettes") 
  
# demonstrating the BrBG palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9], 
           top = [9] * 9,
           bottom = [8] * 9,
           width = 1,
           color = BrBG[9])
  
# demonstrating the PiYG palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9], 
           top = [7] * 9,
           bottom = [6] * 9,
           width = 1,
           color = PiYG[9])
  
# demonstrating the RdGy palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9], 
           top = [5] * 9,
           bottom = [4] * 9,
           width = 1,
           color = RdGy[9])
  
# demonstrating the RdYlGn palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9], 
           top = [3] * 9,
           bottom = [2] * 9,
           width = 1,
           color = RdYlGn[9])
  
# demonstrating the YlGnBu palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8, 9], 
           top = [1] * 9,
           width = 1,
           color = YlGnBu[9])
  
# displaying the model 
show(graph) 
 
 

Output :

Usability Palettes

Bokeh provides us with a palette that is useful for people with color deficiency or color blindness.

Example : We will be demonstrating the usability palette by plotting multiple vertical bars using the vbar() function.




# importing the modules 
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import Colorblind
  
# file to save the model 
output_file("gfg.html") 
         
# instantiating the figure object 
graph = figure(title = "Bokeh Palettes") 
  
# demonstrating the Colorblind palette
graph.vbar(x = [1, 2, 3, 4, 5, 6, 7, 8], 
           top = [1] * 8,
           width = 1,
           color = Colorblind[8])
  
# displaying the model 
show(graph)
 
 

Output :

Large Palettes

The color palettes discussed above might be small for some applications. Bokeh provides us with large palettes that have 256 colors each. There are 7 large palettes :

  • Greys256
  • Inferno256
  • Magma256
  • Plasma256
  • Viridis256
  • Cividis256
  • Turbo256

Example : We will be demonstrating the large palettes by plotting multiple vertical bars using the vbar() function.




# importing the modules 
from bokeh.plotting import figure, output_file, show 
from bokeh.palettes import Greys256, Inferno256, Magma256, Plasma256
from bokeh.palettes import Viridis256, Cividis256, Turbo256
  
# file to save the model 
output_file("gfg.html") 
         
# instantiating the figure object 
graph = figure(title = "Bokeh Palettes") 
  
# demonstrating the Greys256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [20] * 256,
           bottom = [18] * 256,
           width = 1,
           color = Greys256)
  
# demonstrating the Inferno256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [17] * 256,
           bottom = [15] * 256,
           width = 1,
           color = Inferno256)
  
# demonstrating the Magma256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [14] * 256,
           bottom = [12] * 256,
           width = 1,
           color = Magma256)
  
# demonstrating the Plasma256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [11] * 256,
           bottom = [9] * 256,
           width = 1,
           color = Plasma256)
  
# demonstrating the Viridis256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [8] * 256,
           bottom = [6] * 256,
           width = 1,
           color = Viridis256)
  
# demonstrating the Cividis256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [5] * 256,
           bottom = [3] * 256,
           width = 1,
           color = Cividis256)
  
# demonstrating the Turbo256 palette
graph.vbar(x = [i for i in range(256)], 
           top = [2] * 256,
           bottom = [0] * 256,
           width = 1,
           color = Turbo256)
  
# displaying the model 
show(graph) 
 
 

Output :



Next Article
How to add color-picker in Bokeh?

Y

Yash_R
Improve
Article Tags :
  • Python
  • Python-Bokeh
Practice Tags :
  • python

Similar Reads

  • Python Plotly - How to set up a color palette?
    In Plotly a color palette is a set of colors that you can use to make your plots look more attractive. You can set up a color palette to control how the colors in your graph. In this article, we will discuss how to set up a color palette in plotly. Method 1: Setting up the color palette for continuo
    3 min read
  • How To Use Seaborn Color Palette to Color Boxplot?
    Box Plot is the visual representation of the depicting groups of numerical data through their quartiles. Boxplot is also used to detect the outlier in the data set. It captures the summary of the data efficiently with a simple box and whiskers and allows us to compare easily across groups.  Adding t
    3 min read
  • Automatically Cycling Through a Color Palette in Bokeh - Python
    Bokeh is a powerful Python library for creating interactive visualizations for modern web browsers. It offers elegant and concise construction of versatile graphics, and it is particularly useful for creating dashboards and data applications. One of the essential aspects of data visualization is col
    5 min read
  • How to change a color bar in Plotly in Python
    In this article, we will learn how to change a color bar in Plotly Python.  Different types Color-Scale names for Plotlyaggrnyl     burginferno     plasma      rdpu        ylgnbu      mattergeyseragsunset    burgyl      jet         plotly3redorylorbr      solarpiygblackbodycividismagenta     pubu
    2 min read
  • How to add color-picker in Bokeh?
    In this article, we are going to see how to add a color picker widget in bokeh.  Widgets are the best way to make charts more interactive. We can also add widgets in the Bokeh application to provide the best front-end user visualization. Using widgets we can do many things like update charts, connec
    1 min read
  • Python Bokeh - Plotting Square Pins on a Graph
    Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to plot square pins on a graph. Plotting
    2 min read
  • Python | OpenCV BGR color palette with trackbars
    OpenCV is a library of programming functions mainly aimed at real-time computer vision. In this article, Let's create a window which will contain RGB color palette with track bars. By moving the trackbars the value of RGB Colors will change b/w 0 to 255. So using the same, we can find the color with
    2 min read
  • Matplotlib.colors.to_hex() in Python
    Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.colors.to_hex() The matplotlib.colors.to_hex() function is used to convert nu
    2 min read
  • bokeh.plotting.figure.step() function in Python
    Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like notebook, html and server. The Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with
    4 min read
  • Python Bokeh - Plotting Xs on a Graph
    Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to plot Xs on a graph. Plotting Xs on a g
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences