surfplot icon indicating copy to clipboard operation
surfplot copied to clipboard

Question on Color Mapping Zero to White with Arbitrary Value Ranges

Open KGZaker opened this issue 1 year ago • 1 comments

First and foremost, I would like to express my gratitude for creating such a useful package. It has significantly aided my research.

However, I've encountered a specific issue while using the package: I am trying to map a set of numerical values onto a brain surface, where the minimum value is -40 and the maximum is 90. In my case, when utilizing a color map like RdBu, I notice that the value 0 does not correspond to white.

I am looking to find a way to ensure that, regardless of whether the absolute values of the minimum and maximum are equal, the value 0 is always mapped to white. Could you please advise if there is a method or setting within the package that would allow me to achieve this?

Thank you very much for your time and assistance.

KGZaker avatar Mar 26 '24 15:03 KGZaker

Hi @KGZaker ,

Good question! Currently surfplot doesn't handle asymmetrical colourmaps, however there is a way around this that involves creating two data layers: a positive data layer, and a negative data layer.

First, take the data values x, and threshold them x>=0 only to get positive-only data, x_pos. Second, repeat the same step but threshold them x<=0 to obtain negative-only data, x_neg .

Then, take the RdBu colormap and split it into halves. cmasher is a great little library that has a function, get_sub_cmap.

From here you can plot each data, x_pos and x_neg, as it's own layer (e.g., Plot.add_layer()) using the the red and blue colormap halves, respectively. Here you can manually set the colormap limits for each positive and negative layer

danjgale avatar Apr 09 '24 18:04 danjgale