我正在为一个数据帧绘制一个HBar。下面的代码适用于另一个数据帧,但对于当前的数据帧,似乎根本没有输出。在
代码如下:
from bokeh.models import ColumnDataSource, DataRange1d, Plot, LinearAxis, Grid,Label,LabelSet,HoverTool
from bokeh.models.glyphs import HBar
from bokeh.resources import INLINE
import bokeh.io
bokeh.io.output_notebook()
source1 = ColumnDataSource(
data=dict(
GID = Customer_rank.GuestId.head(15).tolist(),
GSale = Customer_rank.FinalSalePrice.head(15).astype(int).tolist()
)
)
GID = Customer_rank.GuestId.tolist()
# hover = HoverTool(tooltips=[
# # ("(x,y)", "(@lat, @lon)"),
# ("Merch_ID", "@ID"),
# ('Revenue','@Sales'),
# ("Visits","@Count")
# ])
p = figure(y_range= ID)
# p.background_fill_color = None
# p.background_fill_alpha = None
# labels = LabelSet(x='Count', y='ID', text='Count', level='glyph',
# y_offset=5, render_mode='canvas',source=source)
# p.add_tools(hover)
p.grid.grid_line_color = None
p.xaxis.visible = None
p.yaxis.axis_line_color = None
p.xaxis.axis_line_color = None
p.xaxis.major_tick_line_color = None
p.xaxis.minor_tick_line_color = None
p.outline_line_alpha = 0.2
H_1= HBar(y='GID',right='GSale',height = 0.5,fill_color="#6C69EB")
# H_2 = HBar(y='ID',right='Sales',height = 0.5)
p.add_glyph(source1, H_1)
# p_2 = p.add_glyph(source, H_2)
# p.add_layout(labels)
show(p)
有问题的数据帧(头部)如下:
^{pr2}$我很困惑为什么代码不呈现一个情节。在
编辑: 我使用上面的代码生成了一个带有以下数据帧的绘图:
Merchants Total_Count
0 LP 198787
1 KC 134952
2 BDR 123668
3 JHU 108698
4 LKW 82122
5 COL 75449
6 POW 70844
7 GTK 69816
8 INM 37715
9 PH 13048
10 BLO 7464
11 BWF 4324
12 HO 4233
13 BKM 2957
14 BIN 1877
以下是调整后的进口笔记本电脑
然后用ID GID更改了行:
^{pr2}$我可以正确地看到Hbar图表(我得到了show和figure的错误,它们没有导入,ID在注释掉时没有定义)
相关问题 更多 >
编程相关推荐