简体   繁体   English

在散景 x 轴上显示月份名称

[英]Display month names on bokeh x-axis

Does anyone know how I can overwrite the x-axis values to display the months of the year in bokeh?有谁知道如何覆盖 x 轴值以在散景中显示一年中的月份?

The graph looks well, and is working as intended, but the x-axis shows numbers up to 12 (as you would expect) - whereas I would like to override this and have it display the month names.该图看起来不错,并且按预期工作,但 x 轴显示的数字最多为 12(如您所料) - 而我想覆盖它并让它显示月份名称。 It's plotting data that comes in this format:它正在绘制这种格式的数据:

{u'amencke': [15, 8, 9, 49, 39, 42, 40, 23, 33, 0, 0, 0], ....} 

Using a simple line plot:使用简单的线图:

for x, y in data.iteritems():
        pMonth = Line(data, title="Sea Bass caught", tools=False, xlabel='Month', ylabel='No. Caught',\
                width=1300, height=600, legend='top_right')

If possible - I'd like the y-axis to display the months - for example the data in this array:如果可能 - 我希望 y 轴显示月份 - 例如这个数组中的数据:

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

Any ideas?有任何想法吗? Bokeh has nice documentation but I couldn't find a way of doing this. Bokeh 有很好的文档,但我找不到这样做的方法。

Cheers, Arthur干杯,亚瑟

Here is a simplified solution这是一个简化的解决方案

data = [15, 8, 9, 49, 39, 42, 40, 23, 33, 0, 0, 0] 
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

p = figure(plot_width=400, plot_height=200)
x = months
y = data
p = figure(x_range = x)
p.line(x,y)
p.circle(x,y, fill_color="white", size=8)
show(p)

Providing the categories as the x_range or y_range explicitly helps.提供类别作为 x_range 或 y_range 明确有帮助。 Bokeh Doc 散景文档

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

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