Python中的Bokeh包:如何使用rgb颜色选项

Python中的Bokeh包:如何使用rgb颜色选项,python,bokeh,Python,Bokeh,假设我有以下代码: from bokeh.plotting import * p= figure(title = 'title',x_axis_label='x',y_axis_label='y') p.circle(-25,25, radius=5, color="black", alpha=0.8) show(p) 我试图在文档中找到如何使用rgb值存储颜色,但找不到它。我的意思如下: p.circle(-25,25, radius=5, color=[0,0,0], alpha=0.8)

假设我有以下代码:

from bokeh.plotting import *
p= figure(title = 'title',x_axis_label='x',y_axis_label='y')
p.circle(-25,25, radius=5, color="black", alpha=0.8)
show(p)
我试图在文档中找到如何使用rgb值存储
颜色
,但找不到它。我的意思如下:

p.circle(-25,25, radius=5, color=[0,0,0], alpha=0.8)

有办法实现吗?

bokeh
支持使用多种方法输入颜色:

  • 命名颜色(如
    绿色
    蓝色
  • RGB十六进制值,如
    #FF3311
  • 表示RGB值的三元组,如
    (0,0,0)
  • 表示RGB Alpha值的4元组,如
    (0,0,0,0.0)
因此,您可以像这样调用函数:

p.circle(-25, 25, radius=5, color=(0, 0, 0), alpha=0.8)
此行为在
bokeh
文档的一节中定义


我这里的示例代码演示了这一点:

#!/usr/bin/env python
from bokeh.plotting import figure, output_file, show

# output to static HTML file
output_file("circle.html", title="circles")

# create a new plot with a title and axis labels, and axis ranges
p = figure(title="circles!", x_axis_label='x', y_axis_label='y',
           y_range=[-50, 50], x_range=[-50, 50])

# add a circle renderer with color options
p.circle(-25, 25, radius=5, color=(0,0,0), alpha=0.8)
p.circle(-10, 5, radius=5, color=(120, 240, 255))

# show the results
show(p)
它生成的绘图如下所示:

当我运行此命令时,上面的代码:

from bokeh.plotting import figure, output_file, show

output_file("circle.html")
p= figure(title = 'title',x_axis_label='x',y_axis_label='y')
p.circle(-25,25, radius=5, color="black", alpha=0.8)
show(p)
生成以下内容:

#!/usr/bin/env python
from bokeh.plotting import figure, output_file, show

# output to static HTML file
output_file("circle.html", title="circles")

# create a new plot with a title and axis labels, and axis ranges
p = figure(title="circles!", x_axis_label='x', y_axis_label='y',
           y_range=[-50, 50], x_range=[-50, 50])

# add a circle renderer with color options
p.circle(-25, 25, radius=5, color=(0,0,0), alpha=0.8)
p.circle(-10, 5, radius=5, color=(120, 240, 255))

# show the results
show(p)

你是说
颜色=(0,0,0)
?:)@哦,哎呀!谢谢你,我试过了,结果是一个白色的圆圈。不应该是黑色的吗?即使我输入了无效的值,例如
color=(30034343,2)
@MpizosDimitris,也会观察到同样的行为-我不确定是什么原因导致了这种情况,我正在运行bokeh 0.9.3,而我刚刚编辑到我的帖子中的代码对我有效。另外,你的为我生成了一个半透明的黑色圆圈。我想这是我的版本。我得到了
bokeh==0.9.0
。谢谢你抽出时间。