Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Surfaces with different colormaps

How can multiple surfaces be plotted on the axes but surfaces uses a different colormap?.

Using colormap("...") changes it for the entire figure, not just a single surface.

Thanks

like image 692
jzz11 Avatar asked Oct 23 '25 08:10

jzz11


1 Answers

Do You mean on same axes?

I haven't found a function that does this directly. But it is possible to pass the desired colors in the surf function.

Way I found: Convert the data to a 0-1 scale and then convert to the desired colormap.

Example with hot and jet colormaps:

tx = ty = linspace (-8, 8, 41)';
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
tz = sin (r) ./ r ;

function normalized = normalize_01(data)
  data_min = min(min(data))
  data_max = max(max(data))
  normalized = (data - data_min)/(data_max - data_min)
endfunction

function rgb = data2rgb(data, color_bits, cmap)
  grays = normalize_01(data)
  indexes = gray2ind(grays, color_bits)
  rgb = ind2rgb(indexes, cmap)
endfunction

color_bits = 128

cmap_1 = hot(color_bits)
rgb_1 = data2rgb(tz, color_bits, cmap_1)
surf(tx, ty, tz, rgb_1)
hold on

cmap_2 = jet(color_bits)
rgb_2 = data2rgb(tz+3, color_bits, cmap_2)
surf(tx, ty, tz+3, rgb_2)

enter image description here

But if you also need a colorbar, this way might not be useful. Unless you find a way to manually add two colorbar like I did with the cmap.

like image 57
Joao_PS Avatar answered Oct 27 '25 04:10

Joao_PS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!