Python Bokeh – Colors Class

28 Jul, 2020
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.
In this article, we will learn about colors in Bokeh. There are 5 different classes for colors in Bokeh :
bokeh.colors.Colorbokeh.colors.HSLbokeh.colors.RGBbokeh.colors.groupsbokeh.colors.names
bokeh.colors.Color
bokeh.colors.HSL
bokeh.colors.RGB
bokeh.colors.groups
bokeh.colors.names
This is the base class representing the color objects. The methods in this class are :
clamp()
copy()
darken()
from_hsl()
from_rgb()
lighten()
to_css()
to_hsl()
to_rgb()
This provides a class to represent colors with HSL format, i.e. Hue, Value and Lightness. 
Example : We will plot a glyph and use the HSL format to color it.
Python3
# importing the modules from bokeh.plotting import figure, output_file, show from bokeh.colors import HSL  # file to save the model output_file("gfg.html")       # instantiating the figure object graph = figure(title = "Bokeh Color")       # the point to be plotted x = 0y = 0  # HSL colorhue = 0saturation = 0.47lightness = 0.58color = HSL(h = hue,            s = saturation,            l = lightness)  # plotting the graph graph.dot(x, y, size = 1000,          color = color.to_rgb())       # displaying the model show(graph)
 
 
Output :
 
 
 
This represents colors by specifying their Red, Green, and Blue channels.
 
Example : We will plot a glyph and use the RGB format to color it in light green.
 
Python3
# importing the modules from bokeh.plotting import figure, output_file, show from bokeh.colors import RGB  # file to save the model output_file("gfg.html")       # instantiating the figure object graph = figure(title = "Bokeh Color")       # the point to be plotted x = 0y = 0  # RGB colorred = 144green = 238blue = 144color = RGB(r = red,            g = green,            b = blue)  # plotting the graph graph.dot(x, y, size = 1000,          color = color)       # displaying the model show(graph)
 
 
Output : 
 
 
 
This represents CSS named colors into useful groups according to the general hue. Each color has its own class with multiple colors of different hues. The list of colors present in this class are :
 
black : gainsboro, lightgray, silver, darkgray, gray, dimgray, lightslategray, slategray, darkslategray, blackblue : lightsteelblue, powderblue, lightblue, skyblue, lightskyblue, deepskyblue, dodgerblue, cornflowerblue, steelblue, royalblue, blue, mediumblue, darkblue, navy, midnightbluebrown : cornsilk, blanchedalmond, bisque, navajowhite, wheat, burlywood, tan, rosybrown, sandybrown, goldenrod, darkgoldenrod, peru, chocolate, saddlebrown, sienna, brown, marooncyan : mediumaquamarine, aqua, cyan, lightcyan, paleturquoise, aquamarine, turquoise, mediumturquoise, darkturquoise, lightseagreen, cadetblue, darkcyan, tealgreen : darkolivegreen, olive, olivedrab, yellowgreen, limegreen, lime, lawngreen, chartreuse, greenyellow, springgreen, mediumspringgreen, lightgreen, palegreen, darkseagreen, mediumseagreen, seagreen, forestgreen, green, darkgreenorange : orangered, tomato, coral, darkorange, orangepink : pink, lightpink, hotpink, deeppink, palevioletred, mediumvioletredpurple : lavender, thistle, plum, violet, orchid, fuchsia, magenta, mediumorchid, mediumpurple, blueviolet, darkviolet, darkorchid, darkmagenta, purple, indigo, darkslateblue, slateblue, mediumslatebluered : lightsalmon, salmon, darksalmon, lightcoral, indianred, crimson, firebrick, darkred, redwhite : white, snow, honeydew, mintcream, azure, aliceblue, ghostwhite, whitesmoke, seashell, beige, oldlace, floralwhite, ivory, antiquewhite, linen, lavenderblush, mistyroseyellow : yellow, lightyellow, lemonchiffon, lightgoldenrodyellow, papayawhip, moccasin, peachpuff, palegoldenrod, khaki, darkkhaki, gold
black : gainsboro, lightgray, silver, darkgray, gray, dimgray, lightslategray, slategray, darkslategray, black
blue : lightsteelblue, powderblue, lightblue, skyblue, lightskyblue, deepskyblue, dodgerblue, cornflowerblue, steelblue, royalblue, blue, mediumblue, darkblue, navy, midnightblue
brown : cornsilk, blanchedalmond, bisque, navajowhite, wheat, burlywood, tan, rosybrown, sandybrown, goldenrod, darkgoldenrod, peru, chocolate, saddlebrown, sienna, brown, maroon
cyan : mediumaquamarine, aqua, cyan, lightcyan, paleturquoise, aquamarine, turquoise, mediumturquoise, darkturquoise, lightseagreen, cadetblue, darkcyan, teal
green : darkolivegreen, olive, olivedrab, yellowgreen, limegreen, lime, lawngreen, chartreuse, greenyellow, springgreen, mediumspringgreen, lightgreen, palegreen, darkseagreen, mediumseagreen, seagreen, forestgreen, green, darkgreen
orange : orangered, tomato, coral, darkorange, orange
pink : pink, lightpink, hotpink, deeppink, palevioletred, mediumvioletred
purple : lavender, thistle, plum, violet, orchid, fuchsia, magenta, mediumorchid, mediumpurple, blueviolet, darkviolet, darkorchid, darkmagenta, purple, indigo, darkslateblue, slateblue, mediumslateblue
red : lightsalmon, salmon, darksalmon, lightcoral, indianred, crimson, firebrick, darkred, red
white : white, snow, honeydew, mintcream, azure, aliceblue, ghostwhite, whitesmoke, seashell, beige, oldlace, floralwhite, ivory, antiquewhite, linen, lavenderblush, mistyrose
yellow : yellow, lightyellow, lemonchiffon, lightgoldenrodyellow, papayawhip, moccasin, peachpuff, palegoldenrod, khaki, darkkhaki, gold
 
Example : We will plot multiple glyphs and use the color groups to color them.
 
Python3
# importing the modules from bokeh.plotting import figure, output_file, show from bokeh.colors.groups import purple, yellow, blue  # file to save the model output_file("gfg.html")       # instantiating the figure object graph = figure(title = "Bokeh Color")       # the point to be plotted x = [-2, 0, 2]y = 0  # color groupscolor = [purple()._colors[purple()._colors.index("Fuchsia")],         yellow()._colors[yellow()._colors.index("Khaki")],         blue()._colors[blue()._colors.index("RoyalBlue")]]  # plotting the graph graph.dot(x, y, size = 1000,          color = color)       # displaying the model show(graph)
Output : 
This class provides us with all the 147 CSS named colors. 
Example : We will plot multiple glyphs and use the color names to color them.
Python3
# importing the modules from bokeh.plotting import figure, output_file, show from bokeh.colors import named  # file to save the model output_file("gfg.html")       # instantiating the figure object graph = figure(title = "Bokeh Color")       # the point to be plotted x = [-3, 0, 3]y = 0  # color namescolor = ["bisque",         "greenyellow",         "magenta"]  # plotting the graph graph.dot(x, y, size = 1000,          color = color)       # displaying the model show(graph)
Output : 
Python-Bokeh
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Iterate over a list in Python
Python Classes and Objects
Introduction To PYTHON