Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(bokeh): Inspect timeseries #6479

Open
wants to merge 3 commits into
base: inspect
Choose a base branch
from
Open

enh(bokeh): Inspect timeseries #6479

wants to merge 3 commits into from

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Dec 16, 2024

Disabling the overlay_aggregate fastpath when we have a selector. A bit of formatting in the applies as it was pretty complicated already.

Code
import itertools

import datashader as ds
import numpy as np
import pandas as pd
import panel as pn

import holoviews as hv
from holoviews.operation.datashader import datashade, dynspread, rasterize

hv.extension("bokeh")

num = 10000
seed = np.random.default_rng(1)


def y(val):
    y = seed.normal(0, 1, num).cumsum()
    if val == 1:
        y[num // 2 : num // 2 + num // 10] = np.nan
    return y + val * 100  # No overlap


dists = [
    pd.DataFrame(
        {
            "x": np.arange(num),
            "y": y(val),
            "val": val,
            "cat": cat,
        }
    )
    for val, cat in [
        (0, "c0"),
        (1, "c1"),
    ]
]

df = pd.concat(dists, ignore_index=True)
curves = hv.Curve(df).groupby("cat").opts(tools=["hover"])
overlay = curves.overlay()


def dynspread_datashade(*args, **kwargs):
    return dynspread(datashade(*args, **kwargs))


def dynspread_rasterize(*args, **kwargs):
    return dynspread(rasterize(*args, **kwargs))


def rasterize_linewidth(*args, **kwargs):
    return rasterize(*args, **dict(kwargs, line_width=10))


def datashade_linewidth(*args, **kwargs):
    return datashade(*args, **dict(kwargs, line_width=10))


ops = (
    rasterize,
    dynspread_rasterize,
    rasterize_linewidth,
    datashade,
    dynspread_datashade,
    datashade_linewidth,
)
aggs = (ds.count(self_intersect=False), ds.by("cat", ds.count(self_intersect=False)))
sels = (None, ds.min("val"))
combinations = itertools.product(ops, aggs, sels)
plots = []
for op, agg, sel in combinations:
    title = f"{op.__name__.replace('_','+')}(agg={type(agg).__name__}, sel={type(sel).__name__ if sel else None})"
    plot = op(overlay, aggregator=agg, selector=sel).opts(
        tools=["hover"], title=title, width=400, height=400
    )
    plots.append(plot)

pn.panel(hv.Layout(plots).cols(4).opts(shared_axes=False)).servable()

image

@hoxbro hoxbro changed the title Inspect timeseries enh: Inspect timeseries Dec 16, 2024
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.79%. Comparing base (48f91a5) to head (4eda559).

Files with missing lines Patch % Lines
holoviews/operation/datashader.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           inspect    #6479      +/-   ##
===========================================
- Coverage    88.79%   88.79%   -0.01%     
===========================================
  Files          323      323              
  Lines        68885    68887       +2     
===========================================
+ Hits         61166    61167       +1     
- Misses        7719     7720       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoxbro hoxbro changed the title enh: Inspect timeseries enh(bokeh): Inspect timeseries Dec 18, 2024
Comment on lines +1377 to +1378
if array.shape[-1] == 1:
array = array.squeeze()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because it would give different colors for a single category. I am not sure if it's worth it, to be honest, but I was a bit confused by the different colors with and without a selector.

Code
import datashader as ds
import numpy as np
import pandas as pd

import holoviews as hv
from holoviews.operation.datashader import datashade, dynspread, rasterize

hv.extension("bokeh")

num = 10000
seed = np.random.default_rng(1)

df = pd.DataFrame({"x": np.arange(num), "y": seed.normal(0, 1, num).cumsum(), "val": 1, "cat": "c0"})
curve = hv.Curve(df)

agg_fn = ds.by("cat", ds.count(self_intersect=False))

p0 = datashade(curve, aggregator=agg_fn, line_width=10, selector=None)
p1 = datashade(curve, aggregator=agg_fn, line_width=10, selector=ds.min("val"))
p0 + p1
Before After
 Screenshot 2024-12-19 15 52 59  Screenshot 2024-12-19 15 54 27

@hoxbro hoxbro marked this pull request as ready for review December 19, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant