I am trying to add tooltips to a plot I have made earlier:
On the x-axis are the marker positions, the y-axis contains the gene positions. The tool tips are currently empty
But when I try to add them I get a RuntimeError.
For the plotting I use a df which contains the marker and gene coordinates (respectively xmar and xgen) and the LOD values. These three columns are taken from three separate lists (xmar, ygen and value):
DFvalue = pd.DataFrame({'xmar':xmar, 'ygen':ygen, 'value':value})
xmar ygen value
0 0 402 5.075381
1 0 708 4.619449
2 1 489 3.817142
3 1 652 4.396806
4 2 500 3.662211
and have another df with names instead of coordinates (to link to the tooltips?). This df again is made from three lists (marname, genname and value):
DFname = pd.DataFrame({'xname':marname, 'yname':genname, 'value':value})
xname yname value
0 c1_00593 AT1G05430 5.075381
1 c1_00593 AT1G05900 4.619449
2 c1_00600 AT1G07790 3.817142
3 c1_00600 AT1G08230 4.396806
4 c1_00789 AT1G08920 3.662211
My code for the plotting itself is as following and I guess something goes wrong with the ColumnDataSource() but I cannot see why or how?
TOOLS= "hover,pan,wheel_zoom,zoom_in,zoom_out,box_zoom,undo,redo,reset,save"
SOURCE = ColumnDataSource(DFvalue)
TOOLTIPS = [
('gene', '@genname'),
('marker', '@marname'),
('LOD score', '@value')
]
#Create figure
p = figure(tools=TOOLS, tooltips=TOOLTIPS)
p.xaxis.axis_label = 'Position genes'
p.yaxis.axis_label = 'Position markers'
p.circle(x=xmar, y=ygen, source=SOURCE, size=6, fill_alpha=0.8)
after running I receive the following error:
p.circle(x=xmar, y=ygen, source=SOURCE, size=6, fill_alpha=0.8)
File "fakesource", line 5, in circle
File "C:\Anaconda3\lib\site-packages\bokeh\plotting\helpers.py", line 757, in func
raise RuntimeError(_GLYPH_SOURCE_MSG % nice_join(incompatible_literal_spec_values,
conjuction="and"))
RuntimeError:
Expected x and y to reference fields in the supplied data source.
When a 'source' argument is passed to a glyph method, values that are sequences
(like lists or arrays) must come from references to data columns in the source.
For instance, as an example:
source = ColumnDataSource(data=dict(x=a_list, y=an_array))
p.circle(x='x', y='y', source=source, ...) # pass column names and a source
Alternatively, *all* data sequences may be provided as literals as long as a
source is *not* provided:
p.circle(x=a_list, y=an_array, ...) # pass actual sequences and no source
