如何让yaxis与Bokeh和Hovertool交互?

2024-03-29 12:29:57 发布

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

我想让我的鼠标悬停工具显示y轴上的条的值。它在显示???相反,这很奇怪。另外,如果有人知道怎么做的话,有没有办法让y轴不与e成科学符号?你知道吗

代码如下:

#RQ Do people who are scared about a loss of privacy own less devices than those who are not?
output_notebook()

categories = ['The Loss of Privacy', "We'll all lose touch with one another", "We'll all be less safe", "I have no fears about a more connected future", "Other"]

#Interactivity
hover = HoverTool(tooltips=[
    ("Biggest Fear", "@x"),
    ("Number of Devices Owned", "@y"),
])

p = figure(x_range = categories, plot_height = 250, plot_width = 1000, title = "Total Devices Owned", tools = [hover])
p.vbar(x = categories, top = [268252,133344,86014,44688,47270], width = 0.5)

p.xgrid.grid_line_color = None
p.y_range.start = 0
p.y_range.end = 300000

p.xaxis.axis_label = "What is your biggest fear as we move towards a more connected future?"
p.yaxis.axis_label = "Amount of Devices Owned"

show(p)

以及图表: Graph


Tags: ofmorerangefutureallareaboutwe
1条回答
网友
1楼 · 发布于 2024-03-29 12:29:57

你需要在代码中做两个修改。首先,要显示悬停工具上的值,请将“@y”替换为“@top”。第二,在“数字”行后加上这一行,得到科学符号:p.left[0]。格式化程序。使用\u=错误

#RQ Do people who are scared about a loss of privacy own less devices than those who are not?
output_notebook()

categories = ['The Loss of Privacy', "We'll all lose touch with one another", "We'll all be less safe", "I have no fears about a more connected future", "Other"]

#Interactivity
hover = HoverTool(tooltips=[
    ("Biggest Fear", "@x"),
    ("Number of Devices Owned", "@top"),
])

p = figure(x_range = categories, plot_height = 250, plot_width = 1000, title = "Total Devices Owned", tools = [hover])
p.left[0].formatter.use_scientific = False ## This line is to get out scientific notation
p.vbar(x = categories, top = [268252,133344,86014,44688,47270], width = 0.5)

p.xgrid.grid_line_color = None
p.y_range.start = 0
p.y_range.end = 300000

p.xaxis.axis_label = "What is your biggest fear as we move towards a more connected future?"
p.yaxis.axis_label = "Amount of Devices Owned"

show(p)

相关问题 更多 >