【发布时间】:2020-02-07 14:23:20
【问题描述】:
我以前用不同的数据做过基本相同的情节,我不完全知道为什么,但是一旦我将 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)
一旦我将 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')
【问题讨论】:
-
数据集中的年份是数字还是字符串?
-
@bigreddot 字符串
-
@bigreddot 那是一个元组,我做了以下操作:
xstr = ' '.join(map(str, rowX))相反得到了一个错误:ERROR:bokeh.core.validation.check:E-1019 (DUPLICATE_FACTORS): FactorRange must specicy a轴的分类因子的唯一列表:发现重复因子:“2”、“0”、“1”、“” -
我并没有真正关注。什么是元组?该消息看起来像您为因子或因子范围提供了单个字符的列表。它应该是(字符串)年份的列表,数据本身(在 CDS 中)也应该是(字符串)年份。
-
@bigreddot 很抱歉造成混乱!我试图将年份添加为字符串,如上所示:
xstr = ' '.join(map(str, rowX)这给了我 1019 错误。在我使用字典之前,我一直在使用散景,如下所示: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}然后将其添加到图中: