【问题标题】:Python Bokeh Stacked Bar Chart - How to display data label inside bars? [duplicate]Python Bokeh Stacked Bar Chart - 如何在条内显示数据标签? [复制]
【发布时间】:2016-04-06 11:45:40
【问题描述】:

我目前正在使用此示例创建带有 Bokeh 的条形图:http://docs.bokeh.org/en/0.11.0/docs/gallery/stacked_bar_chart.html

到目前为止一切正常,但是我找不到像这张图表一样向每个条形添加数据值的方法: http://docs.bokeh.org/en/latest/docs/gallery/elements.html

Bokeh.Charts.Bar 类没有像 Bokeh.Plotting.Figure 那样的 .text() 函数。无论如何,我是否可以将元素图表之类的数据添加到条形图中?我试图挖掘类下面的所有代码,但找不到任何解决方案。非常感谢您的帮助。提前致谢。

【问题讨论】:

    标签: python-2.7 label bokeh stacked-chart


    【解决方案1】:

    几个cmets:

    首先,在不久的将来(可能在0.12 中,但不确定)Chart 类将成为Figure 的子类,这样所有像Figure.text 这样的“字形方法”也将适用图表也是如此。

    不管怎样,Chart 始终是Plot 的子类,这意味着您可以随时使用“低级”字形对象和Plot.add_glyph。这看起来基本上像:

    from bokeh.models.glyphs import  Text
    
    text_glyph = Text(x="x", y="y", x_offset=10, text="foo")
    text_renderer = plot.add_glyph(data_source, text_glyph)
    

    使用Text 字形can be seen here 的完整示例(来自版本0.11.1)。

    最后,就在今天合并了一个新的 PR,为 Bokeh 添加了一个适当的 Label 注释,这将使这种事情变得更加容易。您可以在此处查看 PR:

    https://github.com/bokeh/bokeh/pull/4106

    这项工作将成为0.12 版本的一部分。

    【讨论】:

    • 非常感谢您的回答,bigreddot!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    相关资源
    最近更新 更多