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.

Passing vmin and vmax to colormaps for Volume objects

See original GitHub issue

Hi @marcomusy,

It’s entirely possible that there’s a good way to do this that I’m unaware of - apologies if so.

I’m creating a couple of separate renderings of Volume objects that have scalar values at each point, and coloring those based on those scalar values with a colormap. Each rendering also has a ScalarBar associated with it. I’d like to be able to manually set the vmin and vmax on those volumes and ScalarBars, so that the top and bottom of the color range is consistent across renderings. It seems like this is supported for Mesh objects using pointColors(), but I haven’t found anything similar for Volume objects.

So far the best way I’ve found to do this is to pass a list of tuples to the Volume constructor built from the colormap I want - this gets me a consistent colormap, but the colorbar is not consistent - I’d like all the colorbars to start with the vmin and end with the vmax.

My current approach is something like this:

import vedo

import numpy as np

arr = np.zeros(shape=(100,100,100))

for ii in range(100):
    for jj in range(100):
        for kk in range(100):

            arr[ii,jj,kk] = (((ii-50)**2 + (jj-50)**2 + (kk-50)**2 )**0.5/2)


scalarvals = list(range(0,87))
colorvals = [vedo.colorMap(x, 'turbo', vmin=min(scalarvals), vmax=max(scalarvals)) for x in scalarvals]

mapper = list(zip(scalarvals, colorvals))

vol = vedo.Volume(arr, c=mapper).mode(1).addScalarBar(c='black', size=(100,400), nlabels=2, pos=(0.05,.15), titleFontSize=35)

vedo.show(vol)

I’d much rather just pass a lambda that uses vedo.colorMap() with vmin and vmax arguments to the Volume constructor.

Thank you!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
crsanderfordcommented, Aug 27, 2021

Fantastic, works with my example on my end!

0reactions
marcomusycommented, Aug 27, 2021

just remove .useBounds()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Colormap Normalization — Matplotlib 2.1.2 documentation
The default, linear normalization is matplotlib.colors.Normalize() . Artists that map data to color pass the arguments vmin and vmax to construct a matplotlib....
Read more >
Using perceptually uniform colormaps in Mayavi volumetric ...
AFAIK Mayavi does not come with any perceptually uniform colormaps. I tried naively to just pass it one of Matplotlib's colormaps ...
Read more >
Colormap Choices — PyVista 0.37.0 documentation
Use a Matplotlib, Colorcet, cmocean, or custom colormap when plotting scalar values. ... Colormaps are typically specified by passing the string name of...
Read more >
Adding vmin and vmax to gplt.choropleth · Issue #163 - GitHub
Hi, I've just started using geoplot and I wanted to plot several maps in one figure with one shared colorscale.
Read more >
nilearn.plotting.plot_surf_stat_map
Specifies whether the colorbar should range from -vmax to vmax or from vmin to vmax . Setting to 'auto' will select the latter...
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