How to prevent e from being included in the tooltips numeric display in Python's Bokeh graph

Asked 1 years ago, Updated 1 years ago, 213 views

The tooltips number display, which is displayed by placing the cursor on the right side of the graph displayed by Bokeh, contains e.
I want to prevent this e from appearing, so that the numbers as defined in the original data are displayed.
I would appreciate it if someone could let me know.

 from bokeh.plotting import figure, show, ColumnDataSource
from bokeh.models.tools import HoverTool, CustomJSHover
from bokeh.palettes import d3

dataae = [[0.], 0.12, 0.12, 0.3, 0.0, -0.09, 0.1, 0.08, 0.06, 0.04, 0.03, 0.01, 0.01, 0.01,
          -0.01,  0.  ,  0.  ,  0.01, 0.  ],[ 0.  ,  0.06,  0.18,  0.14,  0.05, -0.6 ,  0.25,  0.18,  0.12,
         0.08,  0.05,  0.06,  0.  ,  0.04,  0.04, -0.04,  0.05,  0.02,
         0.01],[0.  , 0.29, 0.12, 0.16, 0.05, 0.2 , 0.19, 0.26, 0.19, 0.34, 0.22,
        0.19, 0.11, 0.09, 0.08, 0.05, 0.04, 0.03, 0.02],[ 0.  ,  0.6 ,  0.5 ,  0.33,  0.5 , -0.2 ,  0.19,  0.3 ,  0.3 ,
         0.26,  0.12,  0.04,  0.03,  0.04,  0.08,  0.02,  0.03,  0.06,
         0.07],[0.  , 0.36, 0.36, 0.24, 0.03, 0.06, 0.18, 0.28, 0.16, 0.14, 0.13,
        0.15, 0.07, 0.07, 0.06, 0.04, 0.04, 0.04, 0.04],[ 0.  ,  0.16,  0.3 ,  0.13,  0.09, -0.55,  0.21,  0.2 ,  0.19,
         0.14,  0.07,  0.36,  0.04,  0.14,  0.04,  0.02,  0.02,  0.03,
         0.02],[0.  , 0.21, 0.26, 0.1 , 0.05, 0.24, 0.15, 0.08, 0.12, 0.12, 0.11,
        0.11, 0.08, 0.06, 0.23, 0.06, 0.03, 0.02, 0.02],[0.  , 0.4 , 0.17, 0.25, 0.27, 0.5 , 0.08, 0.25, 0.14, 0.23, 0.2 ,
        0.17, 0.08, 0.05, 0.09, 0.06, 0.06, 0.13, 0.04]]

g = ['T9', 'T14', 'S5', 'S10', 'S15', 'S22', 'S25', 'S30', 'S35', 'S40',
     'S45', 'S50', 'S55', 'S60', 'H2', 'H7', 'H12', 'H17', 'H22']
cities=['Kyoto', 'Kobe', 'Sapporo', 'Kawasaki', 'Fukuoka', 'Hiroshima', 'Sendai', 'Saitama'] 
colors=d3 ["Category 10"] [8]

x_custom=CustomJSHover(code=f'''
    constg = {g}
    return "+g [special_vars.segment_index]
''')
p=figure(x_range=g, toolbar_location='right', tools=[HoverTool(formatters={'@x':x_custom}],
           sizing_mode = 'stretch_width', max_width = 700, max_height = 250,
           tooltips="In@x{custom}the population increase rate of @cities is$y",
           title='The Population Transition of Japanese City',
           x_axis_label = 'Year in Japanese Calendar', y_axis_label = 'Populationa Increase Rate',
           width=800, height=350)

source=ColumnDataSource(data=dict(x=[g]*len(datae),y=datae,color=colors,cities=cities))
p. multi_line(xs='x', ys='y', line_color='color', legend_field='cities', source=source)

p.legend.location='center'
p.legend.title = 'The Name of City'
p.legend.title_text_font_style='bold'
p.legend.title_text_font_size='15px'
p.add_layout(p.legend[0], 'right')

show(p)

python bokeh

2023-01-15 21:03

1 Answers

Specify a valid number of digits, such as y{0.00}, when specifying the tools format on line 29.

#Before change
tooltips="In@x{custom}the population increase rate of @cities is$y",
# after modification
tooltips="In@x{custom}the population increase rate of @citiesis$y{0.00}",

References


2023-01-16 07:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.