Plot Stacked Surfaces with Coloring Appropriate for each Individual Surface

3 views (last 30 days)
I'm trying to plot several surfaces on top of each other and have their coloring be appropriate for each individual surface based on the data range, i.e. not including the offset.
The surfaces should be offset as the data is (and how I show in the image below). I just want the surface coloring to be based on if each surface had a mean of zero. What I have tried is this, but it's not getting the colors right.
initial = data{1};
climR = [min(initial(:)) max(initial(:))];
figure;
s1 = surf(data{1}); s1.EdgeColor = 'none'; view([-10.5 15]); clim(climR);
hold on;
s2 = surf(data{2}); s2.EdgeColor = 'none'; view([-10.5 15]);
s3 = surf(data{3}); s3.EdgeColor = 'none'; view([-10.5 15]); hcb=colorbar; title(hcb,'Topo (nm)');
%
Any suggestions? I'd like the figure to look somewhat like the cobbled together image pasted below. The cell array "data.mat" is attached.

Accepted Answer

Adam Danz
Adam Danz on 8 May 2024
Assuming the three surfaces are on the same axes, you can set the cdata for each surface. The cdata can be normalized so that each surface shares the same range of cdata values. Then set clim to that same range to ensure that the colorbar shares that range too.
% Create zdata for 3 data sets
[X,Y] = meshgrid(1:0.5:10,1:20);
data1 = (sin(X) + cos(Y))*6;
data2 = 5*peaks(20) + 100;
[X2,Y2] = meshgrid(-5:.5:5);
data3 = (Y2.*sin(X2) - X2.*cos(Y2))*4 + 200;
% Compute cdata for each data set so that it ranges from [-1,1]
cdata1 = rescale(data1,-1,1);
cdata2 = rescale(data2,-1,1);
cdata3 = rescale(data3,-1,1);
% Plot each surf, specify cdata
figure()
s1 = surf(data1,cdata1,'EdgeColor','none');
hold on
s2 = surf(data2,cdata2,'EdgeColor','none');
s3 = surf(data3,cdata3,'EdgeColor','none');
% Set color range to the range of cdata
clim([-1,1])
% Expand aspect ratio to better see space between surfaces
ax = gca;
ax.PlotBoxAspectRatio(3) = 2;
colorbar()

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!