DS-V
DS-V

Reputation: 123

How to supress scientific notation when using custom html tooltips in bokeh?

I have the following code:

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)

where xmax, is the following list: [1695.2462261723747, 1769.4844621328918]

and the graph looks like this:

enter image description here

I want the number to NOT be in scientific format and I am unsure how to do this, whether it is with the html code or with bokeh. please help!

Upvotes: 1

Views: 604

Answers (1)

Jasper
Jasper

Reputation: 1795

You can reformat the output by adding {(0.0000)} to the hovertool field. Different formats and other examples can be found on this page.

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

Upvotes: 1

Related Questions