简体   繁体   English

散点图上的名义/分类轴

[英]Nominal/categorical axis on a scatter plot

How is it possible to generate a nominal/categorical axis (entries like a, b, c instead of 1,2,3 ) on a scatter plot in Bokeh?如何在散景中的散点图上生成名义/分类轴(像a, b, c这样a, b, c条目而不是1,2,3 )?

Imagine that the following data should be plotted:想象一下应该绘制以下数据:

a  0.5
b  10.0
c  5.0

I tried the following:我尝试了以下方法:

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)

However, this generates an empty plot.但是,这会生成一个空图。 If the x data is changed to x = [1, 2, 3] everything gets plotted as expected.如果x数据更改为x = [1, 2, 3]一切都会按预期绘制。

What can I do to have a, b, c on the x axis?我该怎么做才能使 x 轴上有a, b, c

Based on bigreddot's answer, x_range needs to be set explicitly as follows:根据 bigreddot 的回答, x_range需要明确设置如下:

p = bk.figure(title = "scatter", x_range = x)

This is the complete example:这是完整的示例:

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)

You need to supply the list of categories as the x_range or y_range explicitly.您需要明确提供类别列表作为x_rangey_range See:看:

http://docs.bokeh.org/en/latest/docs/gallery/categorical.html http://docs.bokeh.org/en/latest/docs/gallery/categorical.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM