如何在 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
?
最佳答案
根据 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)
关于python - 散点图上的标称/分类轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29081656/