如何在Bokeh的散点图上生成名义/分类轴(a, b, c
而不是1,2,3
)?
想象一下应该绘制以下数据:
a 0.5
b 10.0
c 5.0
我尝试了以下内容:
import bokeh.plotting as bk
# output to static HTML file
bk.output_file("scatter.html", title="scatter plot example")
x = ['a', 'b', 'c']
y = [0.5, 10.0, 5.0]
p = bk.figure(title = "scatter")
p.circle(x = x, y = y)
bk.show(p)
然而,这会产生一个空图。如果x
数据更改为x = [1, 2, 3]
,则会按预期绘制所有内容。
如何在x轴上设置a, b, c
?
答案 0 :(得分:4)
根据bigreddot的回答,x_range
需要明确设置如下:
p = bk.figure(title = "scatter", x_range = x)
这是完整的例子:
import bokeh.plotting as bk
# output to static HTML file
bk.output_file("scatter.html", title="scatter plot example")
x = ['a', 'b', 'c']
y = [0.5, 10.0, 5.0]
p = bk.figure(title = "scatter", x_range = x)
p.circle(x = x, y = y)
bk.show(p)
答案 1 :(得分:2)
您需要明确提供类别列表x_range
或y_range
。参见:
http://bokeh.pydata.org/en/latest/docs/gallery/categorical.html