【发布时间】:2018-05-22 07:00:18
【问题描述】:
我有以下数据框:
Date Impressions Link_Clicks
2017-05-29 00-00-00 1,492,046 8,093
2017-06-05 00-00-00 845,012 4,864
2017-06-12 00-00-00 1,167,100 6,897
2017-06-19 00-00-00 895,781 4,472
2017-06-26 00-00-00 1,037,839 9,518
2017-07-03 00-00-00 1,139,060 9,668
2017-07-10 00-00-00 1,235,760 9,268
2017-07-17 00-00-00 1,200,906 7,989
2017-07-24 00-00-00 1,214,534 6,991
2017-07-31 00-00-00 1,434,225 7,311
2017-08-07 00-00-00 557,393 2,908
我正在尝试使用已成功完成的 Bokeh 来可视化这一点,但是在实施悬停工具时,它会返回除以 2 的数字。这是一个错误吗?
使用的库:
from bokeh.io import output_notebook, show, push_notebook
from bokeh.io import output_file, show, curdoc
output_notebook()
from bokeh.plotting import figure, ColumnDataSource
from bokeh.models import HoverTool, DatetimeTickFormatter, DataRange1d, CustomJS, Plot, LinearAxis, Grid
from bokeh.charts import Bar, BoxPlot, Donut, HeatMap, Histogram, Line, Scatter, TimeSeries
我的代码可以在下面找到:
source = ColumnDataSource(data=dict(
desc = bar_df.index,
y = bar_df["Link_Clicks"],
))
p = Bar(bar_df, label=bar_df.index, values="Link_Clicks", width=1, source=source, agg='sum',
line_color="white", plot_width=900, plot_height=400, bar_width=0.9, legend=None, toolbar_location="right")
p.add_tools(HoverTool(tooltips=[("Link_Clicks", "@y{1.11}"),
("Date", "@index")]))
p.xaxis.major_label_orientation = 45
show(p)
注意:如果你尝试复制这个,Bokeh 的日期不能是 DateTime 格式;只有字符串。
快速转换:df["Date"] = df["Date"].apply(lambda x: str(x).replace(':','-'))
当悬停在上面时,你可以看到它被 2 完美地整除,这很奇怪。我尝试在 ColumnDataSource 下和悬停工具中乘以 y*2,但仍然没有运气。
有什么想法吗?
【问题讨论】:
-
您使用的是哪个版本的散景?
bokeh.charts已被弃用且不再维护,因此如果这是一个错误,可能值得重新格式化您的代码以获取最新版本。 -
嗨托比 - 你是对的。我已经进行了必要的更改。我现在会发帖。感谢您在这方面帮助我
标签: python graph data-visualization bokeh