如何删除散景中悬停收费的“屏幕信息”?
Posted
技术标签:
【中文标题】如何删除散景中悬停收费的“屏幕信息”?【英文标题】:how can I remove the "screen information" of hover tolls in bokeh? 【发布时间】:2019-12-27 18:51:04 【问题描述】:我使用散景绘制了一个绘图,此外,我使用了“悬停”工具来查看点的值。但我还看到另一个值调用:“屏幕”我想禁用这些值的呈现
我已经尝试了不同的方法,但它不起作用
这是我的代码
tools = ["hover","crosshair","box_select","box_zoom","wheel_zoom","reset"]
p = figure(title=self.select_recension, width=1000, height=800, x_range=(1.5, 22), y_range=(35.5, 47),tools=tools)
for i in self.fs_dict.values():
p.line(i[:,0],i[:,1], color="dodgerblue",legend="Boundary in Omega",line_width=1.5)
co="dfTemp"
p.circle(np.array(self.df_dict[co]['longitude']),np.array(self.df_dict[co]['latitude']), fill_color="dodgerblue",size=6,fill_alpha=.9,line_color="dodgerblue",line_alpha=0.6,legend="Localities in Omega",muted_alpha=0.2)
for i in self.gs_dict.values():
p.line(i[:,0],i[:,1], color="red",legend="Boundary in Xi",line_dash="dashdot",line_width=1.5)
co='dfTempX'
p.circle(np.array(self.df_dict[co]['longitude']),np.array(self.df_dict[co]['latitude']), fill_color="crimson",size=6, fill_alpha=.9, line_color="red",line_alpha=0.6,legend="Localities in Xi")
p.legend.click_policy="hide"
show(p)
正如您在此处看到的,当我将鼠标放在“数据”和“屏幕”上时,我想禁用显示屏幕部分。
【问题讨论】:
【参考方案1】:如果您想显示默认工具提示以外的其他内容,则应在 figure()
中指定工具提示。工具提示应指定为 (label, value) 元组的列表。以 $ 开头的字段是“特殊字段”,例如屏幕位置、索引或字形渲染器的名称。以 @ 开头的字段与 ColumnDataSource 中的列相关联。您想要显示数据源中的 x/y 位置,因此您应该将 @x 和 @y 添加到工具提示中。有关悬停工具和工具提示的更多信息,请参阅this 页面上的文档。
from bokeh.plotting import figure, output_file, show, ColumnDataSource
output_file("toolbar.html")
source = ColumnDataSource(data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
desc=['A', 'b', 'C', 'd', 'E'],
))
TOOLTIPS = [
("index", "$index"),
("(x,y)", "($x, $y)"),
("desc", "@desc"),
]
p = figure(plot_width=400, plot_height=400, tooltips=TOOLTIPS, title="Mouse over the dots", tools="pan,wheel_zoom,hover,reset")
p.circle('x', 'y', size=20, source=source)
show(p)
【讨论】:
感谢您的回复,我已经阅读了该链接,我认为有一种更简单的方法可以使屏幕处于非活动状态,我会尝试您的解决方案,然后告诉您!【参考方案2】:这就是答案
def plot_recension(self,fs_dict,gs_dict,df_dict,select_recension):
"""This function returns the map based on the entered values as follows:
fs_dic ~ dictionary of coastal localities in Omega -->dict
gs_dict ~dictionary of coastal localities in Xi -->dict
df_dic ~ dictionary of all localities -->dict
select_recension ~ either 'Omega ' or -'Xi ' -->string
pay attention to capitalization
"""
tools = ["hover","box_select","box_zoom","wheel_zoom","reset"]
TOOLTIPS = [("index", "$index"),("(x,y)", "($x, $y)")]
p = figure(title=self.select_recension, width=1000, height=800, x_range=(1.5, 22), y_range=(35.5, 47),tooltips=TOOLTIPS,tools=tools)
p.background_fill_color = "beige"
p.background_fill_alpha = 0.5
if select_recension== 'Omega':
Locality="x":list(self.df_dict["dfTemp"]['longitude']),"y":list(self.df_dict["dfTemp"]['latitude'])
source = ColumnDataSource(data=Locality)
view = CDSView(source=source)
for i in self.fs_dict.values():
p.line(i[:,0],i[:,1], color="black",legend="Boundary in Omega",muted_alpha=0.2)
co="dfTemp"
p.circle(x='x', y='y',source=source,view=view, fill_color="blue",size=6,fill_alpha=.9,line_color="blue",line_alpha=0.6,legend="Localities in Omega ",muted_alpha=0.2)
elif select_recension== 'Xi':
Locality="x":list(self.df_dict["dfTempX"]['longitude']),"y":list(self.df_dict["dfTempX"]['latitude'])
source = ColumnDataSource(data=Locality)
view = CDSView(source=source)
for i in self.gs_dict.values():
p.line(i[:,0],i[:,1], color="black",legend="Boundary in Xi ",muted_alpha=0.2,line_dash="dashdot")
co='dfTempX'
p.circle(np.array(self.df_dict[co]['longitude']),np.array(self.df_dict[co]['latitude']), fill_color="red",size=6, fill_alpha=.9, line_color="red",line_alpha=0.6,legend="Localities in Xi",muted_alpha=0.2)
p.legend.click_policy="mute"
show(p)
【讨论】:
以上是关于如何删除散景中悬停收费的“屏幕信息”?的主要内容,如果未能解决你的问题,请参考以下文章