Skip to content

Allow background color and n_colors for the scalarbar#370

Merged
akaszynski merged 1 commit intomasterfrom
scalarbar_background_color
Sep 6, 2019
Merged

Allow background color and n_colors for the scalarbar#370
akaszynski merged 1 commit intomasterfrom
scalarbar_background_color

Conversation

@GuillaumeFavelier
Copy link
Copy Markdown
Contributor

@GuillaumeFavelier GuillaumeFavelier commented Sep 6, 2019

This PR allows the add_scalar_bar() function to use a given background_color in the very specific case where the input colormap uses alpha channel. It also adds a new n_colors parameter to control the number of colors in the bar.

import numpy as np
import pyvista as pv
from matplotlib.colors import ListedColormap
arr = np.linspace([1.0, 0.7, 0.5, 1.],
                  [0., 0., 0., 0.],
                  128)
colors = np.concatenate((arr, np.flip(arr)))
cmap = ListedColormap(colors)

p = pv.Plotter()
p.background_color = 'black'
p.add_mesh(pv.Cone().elevation(), cmap=cmap)
p.add_scalar_bar(title='Elevation (with background_color)',
                 background_color=(0.5, 0.5, 0.5), n_colors=256)
p.show()

image

@akaszynski
Copy link
Copy Markdown
Member

Awesome! Thanks!

Copy link
Copy Markdown
Member

@banesullivan banesullivan left a comment

Choose a reason for hiding this comment

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

We need some tests for this new functionality

self.scalar_bar.SetLookupTable(mapper.lookup_table)
if background_color is not None:
from ..core.common import vtk_to_numpy, numpy_to_vtk
if not isinstance(background_color, collections.Iterable):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should leverage parse_color here incase the user passes a string name of a color to be consistent with the rest of the API

self.scalar_bar = vtk.vtkScalarBarActor()
self.scalar_bar.SetLookupTable(mapper.lookup_table)
if background_color is not None:
from ..core.common import vtk_to_numpy, numpy_to_vtk
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should have an absolute import for this

@banesullivan
Copy link
Copy Markdown
Member

Thanks for adding these new features @GuillaumeFavelier! There are a few concerns I have which I will clean up on the master branch

@GuillaumeFavelier GuillaumeFavelier deleted the scalarbar_background_color branch September 10, 2019 13:17
@GuillaumeFavelier GuillaumeFavelier added the enhancement Changes that enhance the library label Sep 12, 2019
@GuillaumeFavelier GuillaumeFavelier restored the scalarbar_background_color branch September 19, 2019 15:16
@banesullivan banesullivan deleted the scalarbar_background_color branch September 20, 2019 19:50
tkoyama010 pushed a commit that referenced this pull request Nov 12, 2024
Bumps the trame group with 4 updates: [trame](https://github.com/Kitware/trame), [trame-client](https://github.com/Kitware/trame-client), [trame-server](https://github.com/Kitware/trame-server) and [trame-vuetify](https://github.com/Kitware/trame-vuetify).


Updates `trame` from 3.6.3 to 3.6.5
- [Release notes](https://github.com/Kitware/trame/releases)
- [Changelog](https://github.com/Kitware/trame/blob/master/CHANGELOG.md)
- [Commits](Kitware/trame@v3.6.3...v3.6.5)

Updates `trame-client` from 3.2.5 to 3.3.2
- [Release notes](https://github.com/Kitware/trame-client/releases)
- [Changelog](https://github.com/Kitware/trame-client/blob/master/CHANGELOG.md)
- [Commits](Kitware/trame-client@v3.2.5...v3.3.2)

Updates `trame-server` from 3.1.0 to 3.2.3
- [Release notes](https://github.com/Kitware/trame-server/releases)
- [Changelog](https://github.com/Kitware/trame-server/blob/master/CHANGELOG.md)
- [Commits](Kitware/trame-server@v3.1.0...v3.2.3)

Updates `trame-vuetify` from 2.7.0 to 2.7.1
- [Release notes](https://github.com/Kitware/trame-vuetify/releases)
- [Changelog](https://github.com/Kitware/trame-vuetify/blob/master/CHANGELOG.md)
- [Commits](Kitware/trame-vuetify@v2.7.0...v2.7.1)

---
updated-dependencies:
- dependency-name: trame
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: trame
- dependency-name: trame-client
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: trame
- dependency-name: trame-server
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: trame
- dependency-name: trame-vuetify
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: trame
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Changes that enhance the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants