【问题标题】:X and Y axis labels for Bokeh figure散景图的 X 和 Y 轴标签
【发布时间】:2014-07-30 15:44:23
【问题描述】:

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

非常感谢!

【问题讨论】:

    标签: python bokeh


    【解决方案1】:

    看看这个例子:elements.py

    您现在还可以将一般绘图相关选项(plot_widthtitle 等)提供给对figure(...) 的调用而不是渲染器函数(在该示例中为circle

    【讨论】:

    • 为了完整性:如果p = figure(),那么p.xaxis.axis_label = "foo"将x轴的标签设置为foo
    【解决方案2】:

    从 Bokeh 0.11.1 开始,user's guide section on axes 现在显示如何编辑现有轴的属性。做法和之前一样:

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

    【讨论】:

    【解决方案3】:

    这是使用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";
    """)
    

    【讨论】:

    • @tuomastic 不需要任何复杂的(额外的轴,改变可见性)来改变 CustomJS 的轴。见discourse.bokeh.org/t/…
    • @bigreddot 感谢您的提醒。我已经更新了答案以包含建议的方法。如果 p.xaxisp.yaxis 是复数形式:p.xaxesp.yaxes,则 Bokeh 用户会更直观。
    【解决方案4】:
    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 2016-05-01
      • 2019-07-07
      • 1970-01-01
      • 2017-07-10
      • 2017-08-24
      • 1970-01-01
      相关资源
      最近更新 更多