简体   繁体   English

散景图的 X 和 Y 轴标签

[英]X and Y axis labels for Bokeh figure

Does anyone know how to add x and y axis title/labels for a Bokeh figure?有谁知道如何为散景图添加 x 和 y 轴标题/标签? Eg X-axis: time, Y-axis: stock price.例如 X 轴:时间,Y 轴:股票价格。

Thanks a lot!非常感谢!

As of Bokeh 0.11.1, the user's guide section on axes now shows how to edit properties of existing axes.从 Bokeh 0.11.1 开始, 关于轴用户指南部分现在显示了如何编辑现有轴的属性。 The way to do it is the same as before:方法和之前一样:

p = figure(width=300, height=300, x_axis_label='Initial xlabel')
p.xaxis.axis_label = 'New xlabel'

Check out this example: elements.py看看这个例子: elements.py

You can also now give general plot related options ( plot_width , title , etc.) to a call to figure(...) instead of the renderer function ( circle , in that example)您现在还可以为调用figure(...)而不是渲染器函数(在该示例中为circle figure(...)提供与绘图相关的一般选项( plot_widthtitle等)

This is how you can change the axis label using CustomJS :这是使用CustomJS更改轴标签的方法:

p = figure(x_axis_label="Initial y-axis label",
           y_axis_label="Initial x-axis label")

# ...

# p.xaxis and p.yaxis are lists. To operate on actual the axes,
# we need to extract them from the lists first.
callback = CustomJS(args=dict(xaxis=p.xaxis[0],
                              yaxis=p.yaxis[0]), code="""
    xaxis.axis_label = "Updated x-axis label";
    yaxis.axis_label = "Updated y-axis label";
""")
from bokeh.plotting import figure, output_file, show
from bokeh.models.annotations import Title
p = figure(plot_width=1300, plot_height=400,x_axis_type="datetime")
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Stock Price'
p.line(time,stock_price)
t = Title()
t.text = 'Stock Price during year 2018'
p.title = t
show(p)

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

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