question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NdOverlay legends: Style by dim transform association with each of NdOverlay's kdim

See original GitHub issue

When doing e.g. an NdOverlay, the legend has an entry for each Element (see below). For 2 or more key dimensions, this quickly becomes a lot. It would be really nice if instead of listing every single Element, we could style the NdOverlay by setting different Cycle options along the different key dimensions, e.g. along kdim1 we vary line width, along kdim2 the color, along kdim3 the opacity, … As far as styling the Element goes, this would mostly be a convenience, but it could make the associated legends much clearer.

E.g. this is what it currently looks like: screen shot 2019-02-28 at 2 19 31 pm

What the legend could instead look like is that there’s a thick line (no colour) for “measured”, a thin one for “representative”, a blue patch for “overturning”, an orange one for “perennial” (no variation in thickness), and so on.

Or is this too complicated to generalize?

Also, unsure if this is related: #1161

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
philippjfrcommented, Mar 29, 2019

This is now possible by using style mappers, e.g.:

df = pd.DataFrame({
    'Time': np.tile(np.arange(100), 9),
    'y': np.random.randn(900).cumsum(axis=0),
    'gridsize': np.repeat([0, 1, 2, 0, 1, 2, 0, 1, 2], 100),
    'turbulence': np.repeat([0, 0, 0, 1, 1, 1, 2, 2, 2], 100)})

df['label'] = ['Gridsize: %s, Turbulence: %s' % (r.gridsize, r.turbulence) for i, r in df.iterrows()]

curves = hv.Dataset(df, ['Time']).to(hv.Curve, 'Time', ['y', 'gridsize','turbulence'], 'label')
curves.overlay('label').opts(
    opts.Curve(color=dim('gridsize').categorize({0: 'red', 1: 'blue', 2: 'green'}),
               line_dash=dim('turbulence').categorize({0: 'solid', 1: 'dashed', 2: 'dotdash'})),
    opts.NdOverlay(width=900, legend_position='right'))

Screen Shot 2019-03-25 at 7 00 20 PM

I’d like to add a cycle method on dim though so you don’t have to provide an explicit mapping.

1reaction
poplarShiftcommented, Jun 11, 2019

Just to clarify Philipp’s code snippet, it may look like you have to pass extra vdims to do the dim transform, but you can even use dim transforms on kdims of NdOverlays! https://nbviewer.jupyter.org/github/poplarShift/pyviz-recipes/blob/master/notebooks/styling_by_attribute.ipynb

Changing title to reflect that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NdOverlay legends: Style by dim transform association with ...
When doing e.g. an NdOverlay, the legend has an entry for each Element (see below). For 2 or more key dimensions, this quickly...
Read more >
NdOverlay — HoloViews v1.15.3
Title: NdOverlay Container; Dependencies: Matplotlib ... keys and making sure each position in the tuple is assigned a corresponding kdim , NdOverlays allow ......
Read more >
holoviews Changelog - pyup.io
Ensure rangesupdate event fires on all plots with linked axes ... Various bug fixes relating to dim transforms including the use of
Read more >
Format legend in NdOverlay to hide dimension label and ...
Hi. I'm trying to hide the dimension prefix ('b: ') from the legend. Preferably that would be the legend title. I know of...
Read more >
Overlay NdOverlays while keeping color / changing marker
import holoviews as hv from holoviews import opts, dim ... kdim_opts): """ For each given kdim of an Nd holoviews container, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found