如何将RangetoolLink与重叠视图中的holoviews结合使用

2024-05-29 05:24:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在全息视图覆盖图中使用全息视图范围工具链接。但无法达到工作范围。有可能做到这一点吗。?你知道吗

基于这些链接example 1example 2,我尝试了覆盖图而不是单一曲线图的选项。但这不管用。下面我提供了一个具有类似虚拟数据的示例。你知道吗

import pandas as pd
import holoviews as hv
from holoviews import opts
import numpy as np

from holoviews.plotting.links import RangeToolLink

hv.extension('bokeh')


# Genrate Random Data
def randomDataGenerator(noOfSampleDataSets):
    for i in range(noOfSampleDataSets):
        res = np.random.randn(1000).cumsum()
        yield res


# Overlay Plots
overlaid_plot = hv.Overlay([hv.Curve(data)
                     .opts(width=800, height=600, axiswise=True, default_tools=[]) 
                            for data in randomDataGenerator(5)])
# Adjust Source Height
source = overlaid_plot.opts(height=200)

# adjust target plot attributes
target = source.opts(clone=True, width=800, labelled=['y'],)

# Link source and target
rtlink = RangeToolLink(source, target)

# Compose and plot.
(target + source).cols(1).opts(merge_tools=False)

我希望源绘图将显示一个范围工具,如示例中所示,并能够在其中选择一个范围,该范围应选择目标绘图中相同的数据点。你知道吗


Tags: 工具数据import视图示例sourcetargetplot
1条回答
网友
1楼 · 发布于 2024-05-29 05:24:42

以下代码适用于我的情况。我稍微重构了代码。但逻辑还是一样的。因此,如果我们有一个重叠的绘图,链接其中一条曲线,在重叠的绘图工程与所有剩余的曲线。你知道吗

Following code works in a jupyter notebook. Its not tested in other environment.

import holoviews as hv
import numpy as np
hv.extension('bokeh')
from holoviews.plotting.links import RangeToolLink

# Genrate Random Data
def randomDataGenerator(noOfSampleDataSets):
    for i in range(noOfSampleDataSets):
        res = np.random.randn(1000).cumsum()
        yield res



#generate all curves
def getCurves(n):
    for data in randomDataGenerator(n):
        curve = hv.Curve(data)
        yield curve



source_curves, target_curves  = [], []
for curve in getCurves(10):
    # Without relabel, the curve somehow shares the ranging properties. opts with clone=True doesn't help either.
    src = curve.relabel('').opts(width=800, height=200, yaxis=None, default_tools=[]) 
    tgt = curve.opts(width=800, labelled=['y'], toolbar='disable')
    source_curves.append(src)
    target_curves.append(tgt)     

# link RangeTool for the first curves in the list.
RangeToolLink(source_curves[0],target_curves[0])

#Overlay the source and target curves
overlaid_plot_src = hv.Overlay(source_curves).relabel('Source')    
overlaid_plot_tgt = hv.Overlay(target_curves).relabel('Target').opts(height=600)

# layout the plot and render
layout = (overlaid_plot_tgt + overlaid_plot_src).cols(1)
layout.opts(merge_tools=False,shared_axes=False)

相关问题 更多 >

    热门问题