Bokeh图的X和Y轴标签

use*_*508 25 python bokeh

有谁知道如何为散景图添加x和y轴标题/标签?例如X轴:时间,Y轴:股票价格.

非常感谢!

tho*_*olf 34

从Bokeh 0.11.1开始,轴上用户指南部分现在显示如何编辑现有轴的属性.这样做的方法与以前一样:

p = figure(width=300, height=300, x_axis_label='Initial xlabel')
p.xaxis.axis_label = 'New xlabel'
Run Code Online (Sandbox Code Playgroud)

  • 现在的用户指南中也包含很多信息:http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#axes (2认同)

big*_*dot 8

看看这个例子:周期表

您现在还可以将一般情节相关选项(plot_width,title等)提供给调用figure(...)而不是渲染器功能(circle在该示例中)


tuo*_*tik 7

这是您可以使用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";
""")
Run Code Online (Sandbox Code Playgroud)

  • @bigreddot 感谢您的提醒。我已经更新了答案以包含建议的方法。如果“p.xaxis”和“p.yaxis”采用复数形式:“p.xaxes”和“p.yaxes”,对于 Bokeh 用户来说会更直观。 (2认同)