工厂安排和分类vbar图表问题

2024-06-12 05:56:24 发布

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

我用vbar在bokeh/python中绘制一个4级条形图。FactorRange文档中只支持3级(FactorRange level

所以我最多只能有3个级别的分类条形图。我想合并以下两个小节进行比较,怎么可能?在

我想把红色和蓝色的图表放在一个vbarchart中进行比较。在

2 level-3 barchart

下面是我的代码和数据:

代码:

pRX = figure(x_range =[],plot_height=250, plot_width=1000, title="VS.FEGE.RXMAXSPEED", toolbar_location=None,tools="")
pTX = figure(x_range =[],plot_height=250, plot_width=1000, title="VS.FEGE.TXMAXSPEED", toolbar_location=None,tools="")

    x1 = list(tp['SRN'])
    x2 = list(tp['SN'])
    x3 = list(tp['PN'])
    x = [(str(a1), str(a2), str(a3)) for a1, a2, a3 in zip(x1, x2, x3)]
    countRx = list(tp['ID_67194369'])
    countTx = list(tp['ID_67194372'])
    sourceRx = ColumnDataSource(data=dict(x=x, counts=countRx))
    sourceTx = ColumnDataSource(data=dict(x=x, counts=countTx))
    #pRX.x_range=FactorRange(*x)
    pRX.x_range.factors = x
    pTX.x_range.factors = x
    pRX.vbar(x='x', top='counts', width=0.4, source=sourceRx)
    pTX.vbar(x='x', top='counts', width=0.4, color="red", source=sourceTx)
    return



layout = column( pTX, pRX)
curdoc().add_root(layout)

样本数据:

^{pr2}$

Tags: 数据代码plotrangewidthlevellist条形图
1条回答
网友
1楼 · 发布于 2024-06-12 05:56:24

您可以将^{}与嵌套类别一起使用。因为你没有提供完整的代码示例,我不能更新你的。但这里有一个完整的例子,它回避了2级嵌套栏(3级的情况非常相似):

from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, FactorRange
from bokeh.plotting import figure
from bokeh.transform import dodge


output_file("bar_nested.html")

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ['2015', '2016', '2017']

data = {'fruits' : fruits,
        '2015'   : [2, 1, 4, 3, 2, 4],
        '2016'   : [5, 3, 3, 2, 4, 6],
        '2017'   : [3, 2, 4, 4, 5, 3]}

# this creates [ ("Apples", "2015"), ("Apples", "2016"), ("Apples", "2017"), ("Pears", "2015), ... ]
x = [ (fruit, year) for fruit in fruits for year in years ]
counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # like an hstack

source = ColumnDataSource(data=dict(x=x, counts=counts))

p = figure(x_range=FactorRange(*x), plot_height=350, title="Fruit Counts by Year",
           toolbar_location=None, tools="")

p.vbar(x=dodge('x', -0.25, range=p.x_range), top='counts', width=0.4, source=source)
p.vbar(x=dodge('x',  0.25, range=p.x_range), top='counts', width=0.4, source=source, color="red")

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xgrid.grid_line_color = None

show(p)

enter image description here

为了简单起见,这段代码只回避了同一个“x”列两次。在

相关问题 更多 >