Beispiel #1
0
def test_holoviews_link_within_pane(document, comm):
    from bokeh.models.tools import RangeTool
    from holoviews.plotting.links import RangeToolLink

    c1 = hv.Curve([])
    c2 = hv.Curve([])

    RangeToolLink(c1, c2)

    pane = Pane(Pane(hv.Layout([c1, c2]), backend='bokeh'))
    column = pane.get_root(document, comm=comm)

    assert len(column.children) == 1
    subcolumn = column.children[0]
    assert isinstance(subcolumn, BkColumn)
    assert len(subcolumn.children) == 2
    toolbar, subsubcolumn = subcolumn.children
    assert isinstance(subsubcolumn, GridBox)
    assert len(subsubcolumn.children) == 2
    (p1, _, _), (p2, _, _) = subsubcolumn.children

    assert isinstance(p1, Figure)
    assert isinstance(p2, Figure)

    range_tool = subsubcolumn.select_one({'type': RangeTool})
    assert isinstance(range_tool, RangeTool)
    assert range_tool.x_range == p2.x_range
Beispiel #2
0
def test_holoviews_link_within_pane(document, comm):
    from bokeh.models.tools import RangeTool
    from holoviews.plotting.links import RangeToolLink

    c1 = hv.Curve([])
    c2 = hv.Curve([])

    RangeToolLink(c1, c2)

    pane = Pane(hv.Layout([c1, c2]))
    column = pane._get_root(document, comm=comm)

    assert len(column.children) == 1
    subcolumn = column.children[0]
    assert isinstance(subcolumn, BkColumn)
    assert len(subcolumn.children) == 2
    toolbar, subsubcolumn = subcolumn.children
    assert isinstance(subsubcolumn, BkColumn)
    assert len(subsubcolumn.children) == 1
    row = subsubcolumn.children[0]
    assert isinstance(row, BkRow)
    assert len(row.children) == 2
    p1, p2 = row.children

    assert isinstance(p1, Figure)
    assert isinstance(p2, Figure)

    range_tool = row.select_one({'type': RangeTool})
    assert isinstance(range_tool, RangeTool)
    range_tool.x_range = p2.x_range
Beispiel #3
0
def test_holoviews_link_after_adding_item(document, comm):
    from bokeh.models.tools import RangeTool
    from holoviews.plotting.links import RangeToolLink

    c1 = hv.Curve([])
    c2 = hv.Curve([])

    RangeToolLink(c1, c2)

    layout = Row(Pane(c1, backend='bokeh'))
    row = layout.get_root(document, comm=comm)

    assert len(row.children) == 1
    p1, = row.children

    assert isinstance(p1, Figure)
    range_tool = row.select_one({'type': RangeTool})
    assert range_tool is None

    layout.append(Pane(c2, backend='bokeh'))
    _, p2 = row.children
    assert isinstance(p2, Figure)
    range_tool = row.select_one({'type': RangeTool})
    assert isinstance(range_tool, RangeTool)
    assert range_tool.x_range == p2.x_range
Beispiel #4
0
def plot_curve():
    df = download_data(index.value)
    future_df = download_data_predicted(index.value)

    title = index.value + " Exchange Rate"
    # Create stock curve
    past_label = "Past " + title
    future_label = "Predicted Future " + title
    df['label'] = past_label
    future_df['label'] = future_label

    new_df = pd.concat([df, future_df], axis=0)
    curve = hv.Curve(df, 'Date', ('Close', 'label'))
    curve_pred = hv.Curve(future_df, 'Date', ('Close', 'Price'))
    # Labels and layout
    tgt = curve.relabel("Past " + title).opts(  #width=width,
        height=600,
        show_grid=True,
        labelled=['y'],
        default_tools=[hover],
        hooks=[set_tools],
        title=title,
        responsive=True)
    tgt_pred = curve_pred.relabel("Future " + title).opts(  #width=width,
        height=600,
        show_grid=True,
        labelled=['y'],
        default_tools=[hover],
        hooks=[set_tools],
        title=title,
        responsive=True)
    src = curve.opts(height=100,
                     yaxis=None,
                     default_tools=[],
                     color='green',
                     responsive=True)
    src_pred = curve_pred.opts(height=100,
                               yaxis=None,
                               default_tools=[],
                               color='green',
                               responsive=True)

    circle = hv.Scatter(df, 'Date', ('Close', 'Price')).opts(color='green')
    circle_pred = hv.Scatter(future_df, 'Date',
                             ('Close', 'Price')).opts(color='blue')

    RangeToolLink(src, tgt)
    # Merge rangetool
    layout = ((tgt * tgt_pred * circle * circle_pred) +
              (src * src_pred)).cols(1)
    layout.opts(opts.Layout(shared_axes=False, merge_tools=False),
                opts.Curve(toolbar=None), opts.Scatter(size=3))
    print("kepanggil nih viz")
    print(df["Close"][0])
    print(index.value)
    return layout
Beispiel #5
0
 def test_range_tool_link_callback_both_axes(self):
     from bokeh.models import RangeTool
     array = np.random.rand(100, 2)
     src = Curve(array)
     target = Scatter(array)
     RangeToolLink(src, target, axes=['x', 'y'])
     layout = target + src
     plot = bokeh_renderer.get_plot(layout)
     tgt_plot = plot.subplots[(0, 0)].subplots['main']
     src_plot = plot.subplots[(0, 1)].subplots['main']
     range_tool = src_plot.state.select_one({'type': RangeTool})
     self.assertEqual(range_tool.x_range, tgt_plot.handles['x_range'])
     self.assertEqual(range_tool.y_range, tgt_plot.handles['y_range'])
Beispiel #6
0
 def test_range_tool_link_callback_single_axis(self):
     if bokeh_version < '0.13':
         raise SkipTest('RangeTool requires bokeh version >= 0.13')
     from bokeh.models import RangeTool
     array = np.random.rand(100, 2)
     src = Curve(array)
     target = Curve(array)
     RangeToolLink(src, target)
     layout = target + src
     plot = bokeh_renderer.get_plot(layout)
     tgt_plot = plot.subplots[(0, 0)].subplots['main']
     src_plot = plot.subplots[(0, 1)].subplots['main']
     range_tool = src_plot.state.select_one({'type': RangeTool})
     self.assertEqual(range_tool.x_range, tgt_plot.handles['x_range'])
     self.assertIs(range_tool.y_range, None)
Beispiel #7
0
def _raw_plot(raw_curve, title="Voltage versus time", **kwargs):

    tgt = raw_curve.relabel(title).opts(
        width=800,
        height=300,
        labelled=["y"],
        # tools=["pan","box_zoom", "reset"],
        active_tools=["pan"],
    )
    src = raw_curve.opts(width=800, height=100, yaxis=None, default_tools=[])

    RangeToolLink(src, tgt)

    layout = (tgt + src).cols(1)
    layout.opts(opts.Layout(shared_axes=False, merge_tools=False))
    return layout
Beispiel #8
0
def test_holoviews_link_across_panes(document, comm):
    from bokeh.models.tools import RangeTool
    from holoviews.plotting.links import RangeToolLink

    c1 = hv.Curve([])
    c2 = hv.Curve([])

    RangeToolLink(c1, c2)

    layout = Row(c1, c2)
    row = layout._get_root(document, comm=comm)

    assert len(row.children) == 2
    p1, p2 = row.children

    assert isinstance(p1, Figure)
    assert isinstance(p2, Figure)

    range_tool = row.select_one({'type': RangeTool})
    assert isinstance(range_tool, RangeTool)
    range_tool.x_range = p2.x_range
Beispiel #9
0

def change_active_stocks(attr, old, new):
    chosen_stocks_stream.event(active=new)


dmap = hv.DynamicMap(stocks_callback, streams=[chosen_stocks_stream])
olayed = dmap
src_crv = hv.Curve(list(), 'Date', 'Price ($)').opts(height=200,
                                                     default_tools=[])
tgt_crv = hv.Curve(list(), 'Date', 'Price ($)').opts(height=400)
src_olay = hv.Overlay([src_crv, olayed.relabel('')]) \
    .opts(width=800, yaxis=None) \
    .collate() \
    .opts(height=200)
tgt_olay = hv.Overlay([tgt_crv, olayed.relabel('')]) \
    .opts(width=800) \
    .collate() \
    .opts(height=400)
RangeToolLink(src_crv, tgt_crv, axes=['x', 'y'])
plt = (tgt_olay + src_olay).cols(1)
plt.opts(opts.Layout(shared_axes=False, merge_tools=False))

checkbox_group = CheckboxGroup(labels=["AAPL", "GOOG"], active=[0, 1])
checkbox_group.on_change("active", change_active_stocks)

doc = curdoc()
hvplot = renderer.get_plot(plt, doc)  # displayed is the laidout hv
plot = layout([hvplot.state, checkbox_group])
doc.add_root(plot)
Beispiel #10
0
    def view(
        self,
        *,
        channels,
        rscale=None,
        gscale=None,
        bscale=None,
        percentile=98,
        show_miniview=True,
        height=600,
        resolution=900,
    ):
        self.channels = channels
        self.resolution = resolution
        self.rscale = rscale or self.ds.display_interval(
            channels[0], percentile)
        self.gscale = gscale or self.ds.display_interval(
            channels[1], percentile)
        self.bscale = bscale or self.ds.display_interval(
            channels[2], percentile)

        self.setup_streams()
        self.setup_controller(channels=channels)
        self.setup_template(height=height)

        tooltips = [
            ("x", "$x{(0)}"),
            ("y", "$y{(0)}"),
        ]
        hover = HoverTool(tooltips=tooltips)
        self.main = self.mainview().opts(
            clone=True,
            responsive=True,
            hooks=[remove_bokeh_logo],
            default_tools=[hover],
            title=f"Sample: {self.name}",
        )

        boxes = hv.Rectangles([])
        self.box_stream = streams.BoxEdit(
            source=boxes,
            styles={"fill_color": ["yellow", "red", "green", "blue", "cyan"]},
        )
        boxes = boxes.opts(hv.opts.Rectangles(active_tools=[], fill_alpha=0.5))

        overlay = hd.regrid(hv.Image([]), streams=[self.pointer])

        if show_miniview:
            mini = (self.miniview().clone(link=False).opts(
                width=200,
                height=200,
                xaxis=None,
                yaxis=None,
                default_tools=[],
                shared_axes=False,
                hooks=[remove_bokeh_logo],
            ))
            zoom = self.zoomview().opts(
                width=200,
                height=200,
                xaxis=None,
                yaxis=None,
                default_tools=[],
                shared_axes=False,
                hooks=[remove_bokeh_logo],
            )
            RangeToolLink(mini, self.main, axes=["x", "y"])
            self.tmpl.add_panel(
                "A",
                pn.Row(
                    pn.panel(self.main * overlay * boxes),
                    pn.Column(pn.panel(mini), pn.panel(zoom)),
                    width=400,
                    height=280,
                    sizing_mode="scale_both",
                ),
            )
        else:
            self.tmpl.add_panel("A", pn.Row(pn.panel(self.main)))
        self.tmpl.add_panel("C", self.controller)
        return self.tmpl