2

Here the code I wrote. I took the data from pandas DF (not pasted here). The x values are from DF index columns that is a DateTime column. The issue that I want to resolve is in line:

TOOLTIPS = [("index", "$index"),("(Time,Temperature)", "($x, $y)"),]

when I have to change the $x format to a correct format in order to see the the time format in the hover window on the bokeh plot.

see the python code

import datetime as dt
from bokeh.plotting import figure, output_file, show

from bokeh.layouts import gridplot
from bokeh.models import ColumnDataSource, CDSView, BooleanFilter
from bokeh.models import DatetimeTickFormatter



x=df_bases.index

y0=df_bases["base_1"]
y1=df_bases["base_5"]
y2=df_bases["base_12"]



# output to static HTML file
output_file("temperatures from thermocouples.html")



# add some renderers

output_file("Thermocouples temperature.html", title="Thermocouples temperature")

TOOLTIPS = [("index", "$index"),("(Time,Temperature)", "($x, $y)"),]


# create a new plot with a datetime axis type
p = figure( tooltips=TOOLTIPS , plot_width=1250, plot_height=580, x_axis_type="datetime", x_axis_label='Time', 
           y_axis_label='Temperature [°C]', title="Thermocouples temperature") 


p.line(x, y0, legend="thermocouple 1", line_width=1 , color='navy', alpha=1)
p.line(x, y1, legend="thermocouple 5", color="green")
p.line(x, y2, legend="thermocouple 12", line_width=1 , color='orange', alpha=1)#, line_dash="4 4")

p.border_fill_color = "whitesmoke"


p.xaxis.formatter=DatetimeTickFormatter(
    microseconds = ['%Y-%m-%d %H:%M:%S.%f'],
    milliseconds = ['%Y-%m-%d %H:%M:%S.%3N'],
    seconds = ["%Y-%m-%d %H:%M:%S"],
    minsec = ["%Y-%m-%d %H:%M:%S"],
    minutes = ["%Y-%m-%d %H:%M:%S"],
    hourmin = ["%Y-%m-%d %H:%M:%S"],
    hours=["%Y-%m-%d %H:%M:%S"],
    days=["%Y-%m-%d %H:%M:%S"],
    months=["%Y-%m-%d %H:%M:%S"],
    years=["%Y-%m-%d %H:%M:%S"],
)


p.title.align = 'center'





# create a column data source for the plots to share
source = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1, y2=y2))

# create a view of the source for one plot to use
view = CDSView(source=source)




# show the results
show(p)
SBN
  • 51
  • 3

1 Answers1

1

Currently (as of Bokeh 1.2) the hover tool does not have any "always on" mode It only hovers in response to hit-testing glyphs that are added to the plot. Additionally there is no way to apply formatting to "special vars" like $x (that will be possible starting in Bokeh 2.0). Custom formatters can only be applied to hover tooltips for data columns. Given that, my best suggestion is to switch to using @xinstead (which interrogates the "x" data column, not the x mouse position". If you do that, you can use all the techniques in the Formatting Tooltip Fields section of the docs.

Since you did not provide a complete example (no data to run), I can only provide partial untested suggestions:

# use @x{%F} to specify the %F datetime format (or choose another) for the x column
TOOLTIPS = [("index", "$index"),("(Time,Temperature)", "(@x{%F}, $y)")]

# tell bokeh to use the "datetime" formatter for the x column
p.hover.formatters = {'x': 'datetime'}

# just a suggestion, often useful for timeseries plots
p.hover.mode = 'vline'
bigreddot
  • 33,642
  • 5
  • 69
  • 122