danjgale / surfplot

A package for publication-ready brain surface figures
https://surfplot.readthedocs.io/en/latest/
Other
53 stars 14 forks source link

Question on Color Mapping Zero to White with Arbitrary Value Ranges #31

Open KGZaker opened 6 months ago

KGZaker commented 6 months ago

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.

danjgale commented 5 months ago

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