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

Improved support for style mapping constant values #3578

Merged
merged 5 commits into from Mar 26, 2019

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 25, 2019

Add support for style mapping constant values on an NdOverlay or in the dimensions of an element. This finally allows using style mapping to assign styles by NdOverlay value (addressing #3534) or by value dimension values, an example of that is the following:

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

Here we mapped the gridsize dimension to color and the turbulence dimension to the line_dash style.

  • Add tests
  • Add matplotlib support

@philippjfr philippjfr added tag: component: plotting type: enhancement Minor feature or improvement to an existing feature labels Mar 25, 2019
@jlstevens
Copy link
Contributor

Looks good and makes sense!

@jbednar
Copy link
Member

jbednar commented Mar 25, 2019

Nice!

@philippjfr
Copy link
Member Author

Apparently this was already mostly working in matplotlib when mapping value dimensions:

download

and now also works for NdOverlay dimensions:

download (1)

@philippjfr
Copy link
Member Author

Ready to review and merge.

@jlstevens
Copy link
Contributor

Looks good to me and this is definitely useful functionality. Merging.

@jlstevens jlstevens merged commit 8d7f701 into master Mar 26, 2019
@philippjfr philippjfr deleted the constant_style_mapping_fix branch April 29, 2019 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: component: plotting type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants