在bokeh中使用自定义html工具提示时如何抑制科学计数法?

时间:2018-12-03 08:04:43

标签: python html bokeh

我有以下代码:

bk.reset_output() #resets what bokeh outputs file too, as before it was outputting to a html file
bk.output_notebook() #output data to jupyter notepad
# source tells bokeh what data to use and gives it a name which it will use whenever it needs to call the data
source1 = ColumnDataSource(data=dict(x=xnew, y=y_smooth))
source2 = ColumnDataSource(data=dict(x=xmax, y=ymax, desc=xmax, imgs = ['../Documents/cat.jpeg',
                                                                     '../Documents/lebowski.jpg']))

# create a new plot with a title and axis labels
p = bk.figure(plot_width=1000, plot_height=750, title='foobar')
# add a line and a Hover tool that will display the value of x and y at any point along the line
#p.line(x='CCS', y='Intensity', line_width=2, source=source)

hover = HoverTool(names=['needshover'],
    tooltips="""
    <div>
         <span style="font-size: 17px; font-weight: bold;">@desc</span>
    </div>
         <img
                src="@imgs" height="100" alt="@imgs" width="100"
                style="float: left; margin: 0px 15px 15px 0px;"
                border="2"
            ></img>
            """
)
p.add_tools(hover)
p.scatter(x='x', y='y', source=source2, marker="inverted_triangle", size=12, name='needshover')
p.line(x='x', y='y', source=source1)
p.xaxis.axis_label = 'CCSD'
p.yaxis.axis_label = 'Intensity'
# show the results
show(p)

其中xmax是以下列表: [1695.2462261723747,1769.4844621328918]

图形如下:

enter image description here

我希望数字不是科学格式,并且不确定如何执行此操作,无论是html代码还是bokeh。请帮忙!

1 个答案:

答案 0 :(得分:1)

您可以通过在悬停工具字段中添加{(0.0000)}来重新格式化输出。在this页上可以找到不同的格式和其他示例。

hover = HoverTool(names=['needshover'],
    tooltips="""
    <div>
         <span style="font-size: 17px; font-weight: bold;">@desc{(0.0000)}</span>
    </div>
         <img
                src="@imgs" height="100" alt="@imgs" width="100"
                style="float: left; margin: 0px 15px 15px 0px;"
                border="2"
            ></img>
            """
)