Python Bokeh – 颜色类
Bokeh 是一个Python交互式数据可视化。它使用 HTML 和 JavaScript 渲染其绘图。它针对现代 Web 浏览器进行演示,提供具有高性能交互性的新颖图形的优雅、简洁构造。
在本文中,我们将了解散景中的颜色。 Bokeh 中有 5 种不同的颜色类别:
- 散景.colors.Color
- 散景.colors.HSL
- 散景.colors.RGB
- 散景.colors.groups
- 散景.colors.names
散景.colors.Color
这是表示颜色对象的基类。这个类中的方法是:
- 夹钳()
- 复制()
- 变暗()
- from_hsl()
- from_rgb()
- 减轻()
- to_css()
- to_hsl()
- to_rgb()
散景.colors.HSL
这提供了一个类来表示具有HSL格式的颜色,即色调、值和亮度。
示例:我们将绘制一个字形并使用 HSL 格式对其进行着色。
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 = 0
y = 0
# HSL color
hue = 0
saturation = 0.47
lightness = 0.58
color = 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)
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 = 0
y = 0
# RGB color
red = 144
green = 238
blue = 144
color = RGB(r = red,
g = green,
b = blue)
# plotting the graph
graph.dot(x, y, size = 1000,
color = color)
# displaying the model
show(graph)
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 groups
color = [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)
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 names
color = ["bisque",
"greenyellow",
"magenta"]
# plotting the graph
graph.dot(x, y, size = 1000,
color = color)
# displaying the model
show(graph)
输出 :
散景.colors.RGB
这通过指定其红色、绿色和蓝色通道来表示颜色。
示例:我们将绘制一个字形并使用 RGB 格式将其着色为浅绿色。
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 = 0
y = 0
# RGB color
red = 144
green = 238
blue = 144
color = RGB(r = red,
g = green,
b = blue)
# plotting the graph
graph.dot(x, y, size = 1000,
color = color)
# displaying the model
show(graph)
输出 :
散景.colors.groups
这根据一般色调将 CSS 命名颜色表示为有用的组。每种颜色都有自己的类别,具有多种不同色调的颜色。此类中存在的颜色列表是:
- 黑色:收益伯勒,浅灰色,银色,深灰色,灰色,深灰色,lightslategray,slategray,darkslategray,黑色
- 蓝色:浅钢蓝、粉蓝、浅蓝、天蓝、浅天蓝、深天蓝、道奇蓝、矢车菊蓝、钢蓝、宝蓝、蓝、中蓝、深蓝、海军蓝、午夜蓝
- 棕色 :玉米丝, blanchedalmond, bisque, navajowhite, 小麦, burlywood, tan, rosybrown, sandybrown, 黄花菜, darkgoldenrod, peru, Chocolate, saddlebrown, 赭色, brown, maroon
- 青色 : mediumaquamarine, aqua, cyan, lightcyan, paleturquoise, 海蓝宝石, turquoise, mediumturquoise, darkturquoise, lightseagreen, cadetblue, darkcyan, 蓝绿色
- 绿色:深橄榄绿、橄榄绿、橄榄色、黄绿、石灰绿、石灰、草坪绿、黄绿色、绿黄、春绿、中春绿、浅绿、淡绿、深海绿、中海绿、海绿、森林绿、绿、深绿
- 橙色:橙红色、番茄、珊瑚色、深橙色、橙色
- 粉红色:粉色、浅粉色、热粉色、深粉色、淡紫色、中紫色
- 紫色:薰衣草、蓟、李子、紫罗兰、兰花、紫红色、洋红色、中兰、中紫、蓝紫、深紫、黑兰、深洋红色、紫、靛蓝、深石蓝、石板蓝、中石板蓝
- 红色: lightsalmon、salmon、darksalmon、lightcoral、indianred、crimson、firebrick、darkred、red
- 白色:白色,雪,蜜露,薄荷,天蓝色,aliceblue,ghostwhite,whitesmoke,贝壳,米色,oldlace,floralwhite,象牙,古色古香,亚麻,薰衣草,迷雾
- 黄色:黄色、浅黄色、柠檬雪纺、浅金黄色、木瓜鞭、莫卡辛、桃子、palegoldenrod、卡其色、深卡其色、金色
示例:我们将绘制多个字形并使用颜色组为它们着色。
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 groups
color = [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)
输出 :
散景.colors.named
这个类为我们提供了所有147 种 CSS 命名颜色。
示例:我们将绘制多个字形并使用颜色名称为它们着色。
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 names
color = ["bisque",
"greenyellow",
"magenta"]
# plotting the graph
graph.dot(x, y, size = 1000,
color = color)
# displaying the model
show(graph)
输出 :