【问题标题】:How to get y-axis to interact with Bokeh and Hovertool?如何让 y 轴与 Bokeh 和 Hovertool 交互?
【发布时间】:2018-04-05 17:57:39
【问题描述】:

我试图让我的 HoverTool 显示 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)

还有图表:

【问题讨论】:

    标签: python graph bokeh interactive


    【解决方案1】:

    您需要对代码进行两次更改。首先,要在 HoverTool 上显示值,请将“@y”替换为“@top”。二、在“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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多