我正在尝试将工具提示添加到我先前绘制的绘图中:
在x轴上是标记位置,y轴包含基因位置。工具提示当前为空
但是当我试图添加它们时,我得到了一个运行时错误。在
对于绘图,我使用包含标记和基因坐标(分别是xmar
和{xmar
,ygen
和{
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
还有另一个df的名称而不是坐标(链接到工具提示吗?)。这个df又是由三个列表组成的(marname
,genname
和{
我的绘图代码如下所示,我猜ColumnDataSource()
出了问题,但我不知道为什么或者怎么出了问题?在
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)
运行后,我收到以下错误:
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
错误消息包含有关使用错误的所有信息,以及有关如何修复的信息:
您将}传递了实际列表。
source
传递给glyph方法,但也为x=xmar
和{正如错误所说,这是不允许的。如果将}作为列放在}以使用这些列:
^{pr2}$source
传递给glyp,glyp的所有内容都必须来自源代码。你不能混搭。因此,您必须将xmar
和{ColumnDataSource
中,然后配置x
和{您可以“手动”将这些列添加到
source.data
字典中,也可以在调用ColumnDataSource(DFvalue)
之前将这些列添加到数据帧中您的
ColumnDataSource
是从DFvalue
生成的,但您正试图从DFname
获取工具提示数据。 我想如果您在您的ColumnDataSource
中包含其他数据:您可以在
TOOLTIP
中指向所需的数据。相关问题 更多 >
编程相关推荐