MultiPlot#

Multi plot annotations#

Note

What you see in this notebook will depend on whether you’ve run this notebook before and written annotations to the annotations.db database! For reproducibility, the rest of the notebook will assume the annotations.db has been deleted (if it exists).

Setup#

The first thing we need to do is get and plot the data we want to annotate. In this example we will make two different plots: one curve and one image plot.

import holoviews as hv
import numpy as np
from holonote.annotate import Annotator

hv.extension("bokeh")
xs = np.arange("2005-02", "2005-04", dtype="datetime64[D]")
ys = np.sin(np.linspace(0, 5 * np.pi, len(xs)))

curve = hv.Curve((xs, ys), kdims=["TIME"])
curve
xvals = np.linspace(-4, 0, 202)
yvals = np.linspace(4, 0, 202)
xs, ys = np.meshgrid(xvals, yvals)
alpha, beta = 1, 0
ab_data = np.sin(((ys / alpha) ** alpha + beta) * xs)

image = hv.Image(ab_data, kdims=["A", "B"]).opts(cmap="greens")
image

We will now create the annotator with the specification consisting of the key dimensions (kdims) in both of the two plots: TIME, A, and B.

spec = {"TIME": np.datetime64, "A": np.float64, "B": np.float64}
annotator = Annotator(spec, fields=["description"])

Then we can do the same as show in the basic example, and overlaying the annotator on top of both plots.

annotator * curve + annotator * image

Basic operations on annotations#

Using the select tool, you can define a region of interest on both of the plots and run the following cell. For more information check out the basic example.

annotator.add_annotation(description='My first annotation!')

You can set the range of interest programmatically as well:

annotator.set_regions(
    TIME=(np.datetime64("2005-02-13"), np.datetime64("2005-02-16")),
    A=(-0.25, 0.25),
    B=(-0.1, 0.1),
)
annotator.add_annotation(description='A programmatically defined annotation')

To persist these annotations, we call the .commit() method:

annotator.commit()

Simple selection of annotations#

Click on a range region in the plot above and run the following cell to see its UUID:

annotator.selected_index
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Right click to download this notebook from GitHub.