如何去除散景中悬停收费的“屏幕信息”?

问题描述 投票:0回答:3

我使用散景绘制了一个图,此外,我还使用“悬停”工具来查看点的值。但我还看到另一个值调用:“屏幕”我想禁用这些值的呈现

我已经尝试过不同的方法,但它不起作用

这是我的代码

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)

正如您所见,当我将鼠标放在有“数据”和“屏幕”的点上时,我想禁用显示屏幕部分。

python hover bokeh
3个回答
1
投票

如果您想显示默认工具提示之外的其他内容,则应在

figure()
中指定工具提示。工具提示应指定为(标签、值)元组列表。以 $ 开头的字段是“特殊字段”,例如屏幕位置、索引或字形渲染器的名称。以 @ 开头的字段与 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)

0
投票

这就是答案

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)


0
投票

首先将 Hovertooltip 重置为 None,然后根据要求设置值。

hover = HoverTool()
 hover.tooltips = None
 TOOLTIPS = [("(x,y)", "($x, $y)")]
© www.soinside.com 2019 - 2024. All rights reserved.