bokeh类别vbar,x_range不起作用

问题描述 投票:0回答:1

我之前使用不同的数据完成了基本上相同的绘图,我不完全知道为什么,但是一旦我将x_range插入其中,就会坚持使我失败。下面的代码可以正常工作,尽管我没有在xaxis上花很多年的时间。

dfnt = dfn[['Total Transactions', 'Total Non-Occupiers']]
xr = str(dfnt.index.values)
xl = ['Total Transactions', 'Total Non-Occupiers']
ld = {'2010':xl, '2011':xl, '2012':xl, '2013':xl, '2014':xl, '2015':xl, '2016':xl, '2017':xl, '2018':xl}
rowX = ['2010', '2011','2012','2013','2014','2015','2016', '2017', '2018']
#x1 = [(y, t) for y in rowX for t in xl]


sourcent = ColumnDataSource(data=dict( x = list(dfnt.index.values),
                                    y=dfnt['Total Transactions'],
                                    y1=dfnt['Total Non-Occupiers']))
pn = figure(plot_height=350, plot_width=550, title='Properties Transactions', y_axis_label=None, x_axis_label=None, tools = 'pan, wheel_zoom, box_zoom, reset')
pn.vbar(x=dodge('x', 0.0), top='y', width=0.3, source=sourcent, color='#440154', legend=value('Total Transactions'))
pn.vbar(x=dodge('x', -0.35), top='y1', width=0.3, source=sourcent, color='#FDE724', legend=value('Total Non-Occupiers'))
pn.legend.location = 'top_left'
hoverpn = HoverTool()
hoverpn.tooltips=[('Transactions', 'overall @y / non-occupiers @y1')]
pn.add_tools(hoverpn)
tick_labelspn = {'10000':'10K','20000':'20K','30000':'30K','40000':'40K','50000':'50K', '60000':'60K'}
pn.yaxis.major_label_overrides = tick_labelspn
pn.legend.background_fill_alpha=None
pn.legend.border_line_alpha=0
pn.legend.label_text_font_size = "11px"
pn.y_range.end = dfnt.values.max()*1.1+1
pn.legend.click_policy="hide"
pn.title.text_font_size = '15px'
pn.xaxis.major_label_text_font_style = 'bold'
pn.grid.grid_line_color=None
pn.toolbar.autohide = True
show(pn)

without x_range

一旦将x_range添加到其中,条形就会消失。

pn = figure(x_range=FactorRange(*ld),plot_height=350, plot_width=550, title='Properties Transactions', y_axis_label=None, x_axis_label=None, tools = 'pan, wheel_zoom, box_zoom, reset')

以下是数据集或dfnt:dfnt

python bokeh xrange
1个回答
0
投票

感谢@bigreddot,这个人似乎是这个社区中的Bokeh大师。无论如何保持字符串格式。我在CDS中使用df.index作为x,它必须是在CDS外部声明的字符串变量,将在两个位置(CDS / x_range)中使用,如下所示:

rowX = '2010', '2011','2012','2013','2014','2015','2016', '2017', '2018'
sourcent = ColumnDataSource(data=dict( x = rowX,
                                    y=dfnt['Total Transactions'],
                                    y1=dfnt['Total Non-Occupiers']))
pn = figure(x_range=rowX, plot_height=350, plot_width=550, title='Properties Transactions in Ireland', y_axis_label=None, x_axis_label=None, tools = 'pan, wheel_zoom, box_zoom, reset')

哪个会很好用。

© www.soinside.com 2019 - 2024. All rights reserved.