简体   繁体   English

如何使y轴与Bokeh和Hovertool进行交互?

[英]How to get y-axis to interact with Bokeh and Hovertool?

I'm trying to get my HoverTool to show the values for bars on the y-axis. 我正在尝试使我的HoverTool在y轴上显示条的值。 It is showing ??? 它显示??? instead which is weird. 相反,这很奇怪。 Further, if anyone knows how, is there a way to have the y-axis not be in scientific notation with the e? 此外,如果有人知道怎么做,有没有办法使y轴不以e表示科学记号?

This is the code: 这是代码:

#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)

And the Graph: 和图: 图形

You need two changes in your code. 您需要在代码中进行两项更改。 First, to show the value on your HoverTool, replace "@y" by "@top". 首先,要在HoverTool上显示值,请用“ @top”替换“ @y”。 Second, add this line after the "figure" line to get out the scientific notation: p.left[0].formatter.use_scientific = False 其次,在“ figure”行之后添加此行以得出科学记号:p.left [0] .formatter.use_scientific = False

#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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM