Returning GlyphRenderer info to HoverTool

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),

        ("CPS", "$y"),

        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):

    self.document = Document()

    self.session = Session()

    self.session.use_doc('xxxxx')

    self.session.load_document(self.document)

    self.currentElement = "MyElement"

    self.currentIS = "MyIS"

    self.rawColNameMax = "jjj.csv"

    self.normColNameMax = "jjj.csv"

    self.uvColNameMax = "jjj.csv"

     

    self.source = ColumnDataSource()

    self.update_data()

    self.document.add(self.create_plots())

    self.session.store_document(self.document)

def create_plots(self):

    xdr = DataRange1d(sources=[self.source.columns("time")])

    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])

    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)

    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")

    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)

    self.rawplot.below.append(xaxis)

    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")

    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)

    self.rawplot.left.append(yaxis)

    

    for i, cluster in enumerate(clusterList):

    	for fileName in cluster:

    		if fileName in self.source.data.keys():

    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])

    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

    			self.rawplot.renderers.append(cps)

    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)

    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

    			self.rawplot.renderers.append(cps_C)     

    tooltips = [

        ("Time", "$x"),

        ("CPS", "$y"),

        ]

    

    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])

    pan_tool = PanTool()

    reset_tool = ResetTool()

    resize_tool = ResizeTool()

    wheelzoom_tool = WheelZoomTool()

    raw_save_tool = PreviewSaveTool()

    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])

    self.rawplot.renderers.extend([cps, ygrid, xgrid])

    overlay = BoxSelectionOverlay(tool=raw_select_tool)

    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)

Hi,

You can add all the custom data you want to display on HoverTool to the ColumnDataSource and call it from the tooltip. You need to reference to the column name prepending a ‘@’ . Take a look at the HoverTool documentation for more info. Looking at you code I guess that you are feeding self.source ad the self.update_data method. In that case, if you add all your data there (time, filename, keys, etc…) you can call those when you create the glyphs and at the tooltip (with @time for instance).

There are a few examples of tooltip showing ColumnDataSource info. For instance:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/les_mis.py

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/hover.py

Cheers

Fabio

···

On Tuesday, April 28, 2015 at 6:51:11 AM UTC+2, [email protected] wrote:

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),
        ("CPS", "$y"),
        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):
    self.document = Document()
    self.session = Session()
    self.session.use_doc('xxxxx')
    self.session.load_document(self.document)
    self.currentElement = "MyElement"
    self.currentIS = "MyIS"
    self.rawColNameMax = "jjj.csv"
    self.normColNameMax = "jjj.csv"
    self.uvColNameMax = "jjj.csv"
    self.source = ColumnDataSource()
    self.update_data()
    self.document.add(self.create_plots())
    self.session.store_document(self.document)
def create_plots(self):
    xdr = DataRange1d(sources=[self.source.columns("time")])
    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
    self.rawplot.below.append(xaxis)
    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
    self.rawplot.left.append(yaxis)
    for i, cluster in enumerate(clusterList):
    	for fileName in cluster:
    		if fileName in self.source.data.keys():
    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
    			self.rawplot.renderers.append(cps)
    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
    			self.rawplot.renderers.append(cps_C)     
    tooltips = [
        ("Time", "$x"),
        ("CPS", "$y"),
        ]
    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
    pan_tool = PanTool()
    reset_tool = ResetTool()
    resize_tool = ResizeTool()
    wheelzoom_tool = WheelZoomTool()
    raw_save_tool = PreviewSaveTool()
    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
    self.rawplot.renderers.extend([cps, ygrid, xgrid])
    overlay = BoxSelectionOverlay(tool=raw_select_tool)
    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)

Hi,

Does this ‘@’ syntax for the HoverTool work if your column name has a space in it? I haven’t found a way to make these work with the HoverTool, so I have to rename them without the space.

Thanks,

Ross

···

On Tuesday, 28 April 2015 16:56:03 UTC+8, Fabio Pliger wrote:

Hi,

You can add all the custom data you want to display on HoverTool to the ColumnDataSource and call it from the tooltip. You need to reference to the column name prepending a ‘@’ . Take a look at the HoverTool documentation for more info. Looking at you code I guess that you are feeding self.source ad the self.update_data method. In that case, if you add all your data there (time, filename, keys, etc…) you can call those when you create the glyphs and at the tooltip (with @time for instance).

There are a few examples of tooltip showing ColumnDataSource info. For instance:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/les_mis.py

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/hover.py

Cheers

Fabio

On Tuesday, April 28, 2015 at 6:51:11 AM UTC+2, [email protected] wrote:

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),
        ("CPS", "$y"),
        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):
    self.document = Document()
    self.session = Session()
    self.session.use_doc('xxxxx')
    self.session.load_document(self.document)
    self.currentElement = "MyElement"
    self.currentIS = "MyIS"
    self.rawColNameMax = "jjj.csv"
    self.normColNameMax = "jjj.csv"
    self.uvColNameMax = "jjj.csv"
    self.source = ColumnDataSource()
    self.update_data()
    self.document.add(self.create_plots())
    self.session.store_document(self.document)
def create_plots(self):
    xdr = DataRange1d(sources=[self.source.columns("time")])
    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
    self.rawplot.below.append(xaxis)
    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
    self.rawplot.left.append(yaxis)
    for i, cluster in enumerate(clusterList):
    	for fileName in cluster:
    		if fileName in self.source.data.keys():
    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
    			self.rawplot.renderers.append(cps)
    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
    			self.rawplot.renderers.append(cps_C)     
    tooltips = [
        ("Time", "$x"),
        ("CPS", "$y"),
        ]
    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
    pan_tool = PanTool()
    reset_tool = ResetTool()
    resize_tool = ResizeTool()
    wheelzoom_tool = WheelZoomTool()
    raw_save_tool = PreviewSaveTool()
    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
    self.rawplot.renderers.extend([cps, ygrid, xgrid])
    overlay = BoxSelectionOverlay(tool=raw_select_tool)
    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)

Hi Fabio and Ross,

Thanks for sending those examples through. My issue is that I would like to present something about the series of points, rather than point-by-point data. In my case, it would be great if a name could be attached to the series (perhaps in the GlyphRenderer stage?)

Does Ross’ idea of @columnName work? If so, I haven’t seen it in the examples or documentation, but it does sound exactly like what I’m looking for.

Thanks,

Bence

···

On Wednesday, April 29, 2015 at 12:38:10 PM UTC+10, Ross Moore wrote:

Hi,

Does this ‘@’ syntax for the HoverTool work if your column name has a space in it? I haven’t found a way to make these work with the HoverTool, so I have to rename them without the space.

Thanks,

Ross

On Tuesday, 28 April 2015 16:56:03 UTC+8, Fabio Pliger wrote:

Hi,

You can add all the custom data you want to display on HoverTool to the ColumnDataSource and call it from the tooltip. You need to reference to the column name prepending a ‘@’ . Take a look at the HoverTool documentation for more info. Looking at you code I guess that you are feeding self.source ad the self.update_data method. In that case, if you add all your data there (time, filename, keys, etc…) you can call those when you create the glyphs and at the tooltip (with @time for instance).

There are a few examples of tooltip showing ColumnDataSource info. For instance:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/les_mis.py

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/hover.py

Cheers

Fabio

On Tuesday, April 28, 2015 at 6:51:11 AM UTC+2, [email protected] wrote:

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),
        ("CPS", "$y"),
        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):
    self.document = Document()
    self.session = Session()
    self.session.use_doc('xxxxx')
    self.session.load_document(self.document)
    self.currentElement = "MyElement"
    self.currentIS = "MyIS"
    self.rawColNameMax = "jjj.csv"
    self.normColNameMax = "jjj.csv"
    self.uvColNameMax = "jjj.csv"
    self.source = ColumnDataSource()
    self.update_data()
    self.document.add(self.create_plots())
    self.session.store_document(self.document)
def create_plots(self):
    xdr = DataRange1d(sources=[self.source.columns("time")])
    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
    self.rawplot.below.append(xaxis)
    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
    self.rawplot.left.append(yaxis)
    for i, cluster in enumerate(clusterList):
    	for fileName in cluster:
    		if fileName in self.source.data.keys():
    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
    			self.rawplot.renderers.append(cps)
    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
    			self.rawplot.renderers.append(cps_C)     
    tooltips = [
        ("Time", "$x"),
        ("CPS", "$y"),
        ]
    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
    pan_tool = PanTool()
    reset_tool = ResetTool()
    resize_tool = ResizeTool()
    wheelzoom_tool = WheelZoomTool()
    raw_save_tool = PreviewSaveTool()
    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
    self.rawplot.renderers.extend([cps, ygrid, xgrid])
    overlay = BoxSelectionOverlay(tool=raw_select_tool)
    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)

Ah. Well in that case you could put the information about the series (perhaps the string “This series was collected on Thursday”) into every row in a new column in your source. You’d name the column “SeriesTipInfo” or whatever, then reference the it in the HoverTool with @SeriesTipInfo. e.g. your source might be:
source:
x,y,SeriesTipInfo

1,3.5,“This series was collected on Thursday”

2,3.4,“This series was collected on Thursday”

3,3.8,“This series was collected on Thursday”

source2:

x,y,SeriesTipInfo

1,4.5,“This series was collected on Friday”

2,4.2,“This series was collected on Friday”

3,5.8,“This series was collected on Friday”

You’re plotting a number of series I assume - you can prep your scatter glyphs:

s=Scatter(<>)

then add the glyph to your figure (named f):

f.add_glyph(source,s)

then add another series:

f.add_glyph(source2,s)

···

On Wednesday, 29 April 2015 11:57:09 UTC+8, [email protected] wrote:

Hi Fabio and Ross,

Thanks for sending those examples through. My issue is that I would like to present something about the series of points, rather than point-by-point data. In my case, it would be great if a name could be attached to the series (perhaps in the GlyphRenderer stage?)

Does Ross’ idea of @columnName work? If so, I haven’t seen it in the examples or documentation, but it does sound exactly like what I’m looking for.

Thanks,

Bence

On Wednesday, April 29, 2015 at 12:38:10 PM UTC+10, Ross Moore wrote:

Hi,

Does this ‘@’ syntax for the HoverTool work if your column name has a space in it? I haven’t found a way to make these work with the HoverTool, so I have to rename them without the space.

Thanks,

Ross

On Tuesday, 28 April 2015 16:56:03 UTC+8, Fabio Pliger wrote:

Hi,

You can add all the custom data you want to display on HoverTool to the ColumnDataSource and call it from the tooltip. You need to reference to the column name prepending a ‘@’ . Take a look at the HoverTool documentation for more info. Looking at you code I guess that you are feeding self.source ad the self.update_data method. In that case, if you add all your data there (time, filename, keys, etc…) you can call those when you create the glyphs and at the tooltip (with @time for instance).

There are a few examples of tooltip showing ColumnDataSource info. For instance:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/les_mis.py

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/hover.py

Cheers

Fabio

On Tuesday, April 28, 2015 at 6:51:11 AM UTC+2, [email protected] wrote:

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),
        ("CPS", "$y"),
        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):
    self.document = Document()
    self.session = Session()
    self.session.use_doc('xxxxx')
    self.session.load_document(self.document)
    self.currentElement = "MyElement"
    self.currentIS = "MyIS"
    self.rawColNameMax = "jjj.csv"
    self.normColNameMax = "jjj.csv"
    self.uvColNameMax = "jjj.csv"
    self.source = ColumnDataSource()
    self.update_data()
    self.document.add(self.create_plots())
    self.session.store_document(self.document)
def create_plots(self):
    xdr = DataRange1d(sources=[self.source.columns("time")])
    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
    self.rawplot.below.append(xaxis)
    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
    self.rawplot.left.append(yaxis)
    for i, cluster in enumerate(clusterList):
    	for fileName in cluster:
    		if fileName in self.source.data.keys():
    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
    			self.rawplot.renderers.append(cps)
    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
    			self.rawplot.renderers.append(cps_C)     
    tooltips = [
        ("Time", "$x"),
        ("CPS", "$y"),
        ]
    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
    pan_tool = PanTool()
    reset_tool = ResetTool()
    resize_tool = ResizeTool()
    wheelzoom_tool = WheelZoomTool()
    raw_save_tool = PreviewSaveTool()
    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
    self.rawplot.renderers.extend([cps, ygrid, xgrid])
    overlay = BoxSelectionOverlay(tool=raw_select_tool)
    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)

Hi Ross,

Thanks for your suggestion. My data are actually columns in a pandas dataframe (each line is a column). E.g.

Sample1 Sample2 Sample3

10.4 24.2 15.4

11.3 27.4 16.6

11.1 25.6 13.4

etc etc

If I was to create a new column to hold the SeriesTipInfo, I would need a new column for every data column. That’s why I was excited about your suggestion about ColumnName. If that could be returned, it would be totally sufficient (I just want Sample1 to come up when I hover over the Sample1 data).

Many thanks for your suggestion,

Bence

···

On Wednesday, April 29, 2015 at 4:06:42 PM UTC+10, Ross Moore wrote:

Ah. Well in that case you could put the information about the series (perhaps the string “This series was collected on Thursday”) into every row in a new column in your source. You’d name the column “SeriesTipInfo” or whatever, then reference the it in the HoverTool with @SeriesTipInfo. e.g. your source might be:
source:
x,y,SeriesTipInfo

1,3.5,“This series was collected on Thursday”

2,3.4,“This series was collected on Thursday”

3,3.8,“This series was collected on Thursday”

source2:

x,y,SeriesTipInfo

1,4.5,“This series was collected on Friday”

2,4.2,“This series was collected on Friday”

3,5.8,“This series was collected on Friday”

You’re plotting a number of series I assume - you can prep your scatter glyphs:

s=Scatter(<>)

then add the glyph to your figure (named f):

f.add_glyph(source,s)

then add another series:

f.add_glyph(source2,s)

On Wednesday, 29 April 2015 11:57:09 UTC+8, [email protected] wrote:

Hi Fabio and Ross,

Thanks for sending those examples through. My issue is that I would like to present something about the series of points, rather than point-by-point data. In my case, it would be great if a name could be attached to the series (perhaps in the GlyphRenderer stage?)

Does Ross’ idea of @columnName work? If so, I haven’t seen it in the examples or documentation, but it does sound exactly like what I’m looking for.

Thanks,

Bence

On Wednesday, April 29, 2015 at 12:38:10 PM UTC+10, Ross Moore wrote:

Hi,

Does this ‘@’ syntax for the HoverTool work if your column name has a space in it? I haven’t found a way to make these work with the HoverTool, so I have to rename them without the space.

Thanks,

Ross

On Tuesday, 28 April 2015 16:56:03 UTC+8, Fabio Pliger wrote:

Hi,

You can add all the custom data you want to display on HoverTool to the ColumnDataSource and call it from the tooltip. You need to reference to the column name prepending a ‘@’ . Take a look at the HoverTool documentation for more info. Looking at you code I guess that you are feeding self.source ad the self.update_data method. In that case, if you add all your data there (time, filename, keys, etc…) you can call those when you create the glyphs and at the tooltip (with @time for instance).

There are a few examples of tooltip showing ColumnDataSource info. For instance:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/les_mis.py

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/hover.py

Cheers

Fabio

On Tuesday, April 28, 2015 at 6:51:11 AM UTC+2, [email protected] wrote:

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),
        ("CPS", "$y"),
        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):
    self.document = Document()
    self.session = Session()
    self.session.use_doc('xxxxx')
    self.session.load_document(self.document)
    self.currentElement = "MyElement"
    self.currentIS = "MyIS"
    self.rawColNameMax = "jjj.csv"
    self.normColNameMax = "jjj.csv"
    self.uvColNameMax = "jjj.csv"
    self.source = ColumnDataSource()
    self.update_data()
    self.document.add(self.create_plots())
    self.session.store_document(self.document)
def create_plots(self):
    xdr = DataRange1d(sources=[self.source.columns("time")])
    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
    self.rawplot.below.append(xaxis)
    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
    self.rawplot.left.append(yaxis)
    for i, cluster in enumerate(clusterList):
    	for fileName in cluster:
    		if fileName in self.source.data.keys():
    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
    			self.rawplot.renderers.append(cps)
    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
    			self.rawplot.renderers.append(cps_C)     
    tooltips = [
        ("Time", "$x"),
        ("CPS", "$y"),
        ]
    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
    pan_tool = PanTool()
    reset_tool = ResetTool()
    resize_tool = ResizeTool()
    wheelzoom_tool = WheelZoomTool()
    raw_save_tool = PreviewSaveTool()
    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
    self.rawplot.renderers.extend([cps, ygrid, xgrid])
    overlay = BoxSelectionOverlay(tool=raw_select_tool)
    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)

I am facing the same issue. Any updates here? It might be handy if a new $ reference could be added to get at the column_names attribute on the ColumndataSource

Thanks,

Gus

···

On Wednesday, April 29, 2015 at 1:34:15 AM UTC-5, [email protected] wrote:

Hi Ross,

Thanks for your suggestion. My data are actually columns in a pandas dataframe (each line is a column). E.g.

Sample1 Sample2 Sample3

10.4 24.2 15.4

11.3 27.4 16.6

11.1 25.6 13.4

etc etc

If I was to create a new column to hold the SeriesTipInfo, I would need a new column for every data column. That’s why I was excited about your suggestion about ColumnName. If that could be returned, it would be totally sufficient (I just want Sample1 to come up when I hover over the Sample1 data).

Many thanks for your suggestion,

Bence

On Wednesday, April 29, 2015 at 4:06:42 PM UTC+10, Ross Moore wrote:

Ah. Well in that case you could put the information about the series (perhaps the string “This series was collected on Thursday”) into every row in a new column in your source. You’d name the column “SeriesTipInfo” or whatever, then reference the it in the HoverTool with @SeriesTipInfo. e.g. your source might be:
source:
x,y,SeriesTipInfo

1,3.5,“This series was collected on Thursday”

2,3.4,“This series was collected on Thursday”

3,3.8,“This series was collected on Thursday”

source2:

x,y,SeriesTipInfo

1,4.5,“This series was collected on Friday”

2,4.2,“This series was collected on Friday”

3,5.8,“This series was collected on Friday”

You’re plotting a number of series I assume - you can prep your scatter glyphs:

s=Scatter(<>)

then add the glyph to your figure (named f):

f.add_glyph(source,s)

then add another series:

f.add_glyph(source2,s)

On Wednesday, 29 April 2015 11:57:09 UTC+8, [email protected] wrote:

Hi Fabio and Ross,

Thanks for sending those examples through. My issue is that I would like to present something about the series of points, rather than point-by-point data. In my case, it would be great if a name could be attached to the series (perhaps in the GlyphRenderer stage?)

Does Ross’ idea of @columnName work? If so, I haven’t seen it in the examples or documentation, but it does sound exactly like what I’m looking for.

Thanks,

Bence

On Wednesday, April 29, 2015 at 12:38:10 PM UTC+10, Ross Moore wrote:

Hi,

Does this ‘@’ syntax for the HoverTool work if your column name has a space in it? I haven’t found a way to make these work with the HoverTool, so I have to rename them without the space.

Thanks,

Ross

On Tuesday, 28 April 2015 16:56:03 UTC+8, Fabio Pliger wrote:

Hi,

You can add all the custom data you want to display on HoverTool to the ColumnDataSource and call it from the tooltip. You need to reference to the column name prepending a ‘@’ . Take a look at the HoverTool documentation for more info. Looking at you code I guess that you are feeding self.source ad the self.update_data method. In that case, if you add all your data there (time, filename, keys, etc…) you can call those when you create the glyphs and at the tooltip (with @time for instance).

There are a few examples of tooltip showing ColumnDataSource info. For instance:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/les_mis.py

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/hover.py

Cheers

Fabio

On Tuesday, April 28, 2015 at 6:51:11 AM UTC+2, [email protected] wrote:

Hi,

I am trying to plot a bunch of samples collected over time as lines in a bokeh-server app (following the example in data_tables, but adding the plot as part of the object (self.rawplot below). In a particular plot, there may be 20-50 lines. Each is rendered separately, via:

cps_glyph = Line(x=“time”, y=fileName, line_color = listOfTraceColours[i])

cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)

self.rawplot.renderers.append(cps)

This is called a bunch of times within a loop so that each line has a color related to what group of samples it belongs to.

My issue comes when I use the hover tool. I know that the hover tool doesn’t work with Line data, so I use Circle exactly the same as above:

cps_glyph_C = Circle(x=“time”, y=fileName) #, line_alpha = 0, fill_alpha = 0)

cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)

self.rawplot.renderers.append(cps_C)

Eventually, these circles will be invisible (hence the line and fill alpha = 0 bit). I add the hover tool via:

tooltips = [

        ("Time", "$x"),
        ("CPS", "$y"),
        ]        

raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)

This works fine showing the x and y positions. However, I would love it if it was also able to display the name of the sample it was hitting. My guess is that it could return the name of the renderer it has hit, or something similar if the rendered had a name argument (e.g. cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C, name=fileName).

Is there some workaround for this case. Any help would be much appreciated. Below is a bit more of my code to illustrate how I’m using it:

class DataTables(object):

def __init__(self):
    self.document = Document()
    self.session = Session()
    self.session.use_doc('xxxxx')
    self.session.load_document(self.document)
    self.currentElement = "MyElement"
    self.currentIS = "MyIS"
    self.rawColNameMax = "jjj.csv"
    self.normColNameMax = "jjj.csv"
    self.uvColNameMax = "jjj.csv"
    self.source = ColumnDataSource()
    self.update_data()
    self.document.add(self.create_plots())
    self.session.store_document(self.document)
def create_plots(self):
    xdr = DataRange1d(sources=[self.source.columns("time")])
    ydr = DataRange1d(sources=[self.source.columns(self.rawColNameMax)])
    self.rawplot = Plot(title=self.currentElement, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
    xaxis = LinearAxis(plot=self.rawplot, axis_label = "Time (s)")
    xgrid = Grid(plot=self.rawplot, dimension=0, ticker=xaxis.ticker)
    self.rawplot.below.append(xaxis)
    yaxis = LinearAxis(plot=self.rawplot, axis_label = "Raw CPS")
    ygrid = Grid(plot=self.rawplot, dimension=1, ticker=yaxis.ticker)
    self.rawplot.left.append(yaxis)
    for i, cluster in enumerate(clusterList):
    	for fileName in cluster:
    		if fileName in self.source.data.keys():
    			cps_glyph = Line(x="time", y=fileName, line_color = listOfTraceColours[i])
    			cps = GlyphRenderer(data_source=self.source, glyph = cps_glyph)
    			self.rawplot.renderers.append(cps)
    			cps_glyph_C = Circle(x="time", y=fileName) #, line_alpha = 0, fill_alpha = 0)
    			cps_C = GlyphRenderer(data_source=self.source, glyph=cps_glyph_C)
    			self.rawplot.renderers.append(cps_C)     
    tooltips = [
        ("Time", "$x"),
        ("CPS", "$y"),
        ]
    raw_hover_tool = HoverTool(plot=self.rawplot, tooltips=tooltips)
    raw_select_tool = BoxSelectTool(plot=self.rawplot, dimensions=['width'])
    pan_tool = PanTool()
    reset_tool = ResetTool()
    resize_tool = ResizeTool()
    wheelzoom_tool = WheelZoomTool()
    raw_save_tool = PreviewSaveTool()
    self.rawplot.tools.extend([pan_tool, raw_hover_tool, raw_select_tool, reset_tool, resize_tool, wheelzoom_tool, raw_save_tool])
    self.rawplot.renderers.extend([cps, ygrid, xgrid])
    overlay = BoxSelectionOverlay(tool=raw_select_tool)
    self.rawplot.add_layout(overlay)

if name == “main”:

data_tables = DataTables()

data_tables.run(True)