如何在bokeh中组合多个条形图?

2024-10-01 11:36:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在同一个图上画两个条形图。在

一个只有正值,一个只有负值。在

我想要绿色的正条(在x轴上方)和红色的负条(在x轴下方)

问题:

1。是否可以使用博克图表接口?

2。如果没有,如何使用较低级别创建条形图博克。绘图接口?(而不是更高的级别博克图表接口)


Tags: 绘图图表级别条形图绿色红色负值负条
2条回答

编辑:下面的答案已经过时几年了。现在,各种条形图(堆叠、分组、彩色映射)都变得简单和容易。有关许多示例,请参见《用户指南》的本节:

https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html


1. 我试着用高级条形图的方法做多个条形图,但是我不能达到我想要的结果,所以我使用了绘图界面。在

2. 这就是你要找的吗?在

    from bokeh.plotting import figure, output_file, show

    plot = figure(width=600, height=600, x_range=(0,50), y_range=(-10,10))

    plot.quad(top=[10],bottom=[0],left=[1],right=[2], color='green', line_color='black', legend='positive')
    plot.quad(top=[12],bottom=[0],left=[2],right=[3], color='green', line_color='black', legend='positive')
    plot.quad(top=[1],bottom=[0],left=[3],right=[4], color='green', line_color='black', legend='positive')
    plot.quad(top=[2],bottom=[0],left=[4],right=[5], color='green', line_color='black', legend='positive')
    plot.quad(top=[3],bottom=[0],left=[5],right=[6], color='green', line_color='black', legend='positive')
    plot.quad(top=[4],bottom=[0],left=[6],right=[7], color='green', line_color='black', legend='positive')

    plot.quad(top=[-5],bottom=[0],left=[1],right=[2], color='red', line_color='black', legend='negative')
    plot.quad(top=[-6],bottom=[0],left=[2],right=[3], color='red', line_color='black', legend='negative')
    plot.quad(top=[-2],bottom=[0],left=[3],right=[4], color='red', line_color='black', legend='negative')
    plot.quad(top=[-8],bottom=[0],left=[4],right=[5], color='red', line_color='black', legend='negative')
    plot.quad(top=[-9],bottom=[0],left=[5],right=[6], color='red', line_color='black', legend='negative')
    plot.quad(top=[-10],bottom=[0],left=[6],right=[7], color='red', line_color='black', legend='negative')

    output_file('test.html')
    show(plot)

您可以使用两个vbar_stack调用:

volume_figure.vbar_stack(["buys"], x='timestamp', width=1.0, color=[colors.turquoise], source=source)
volume_figure.vbar_stack(["sells"], x='timestamp', width=1.0, color=[colors.tomato], source=source)

一般来说,条形图在docs部分Handling Categorical Data中有详细的描述

相关问题 更多 >