필터 지우기
필터 지우기

How to match colorbar with colormap ranges in surf?

조회 수: 15 (최근 30일)
Daniel Melendrez
Daniel Melendrez 2022년 9월 2일
댓글: Daniel Melendrez 2022년 9월 6일
I have a data set that contains values from a certain electronic circuit (voltages (VL), currents (io) and Load resistances (RL)). The size of these arrays is 10x10(x6). (EDITED. I mistakently said 5 times before)
The following code creates the result shown below:
for vsPtr = 1:numel(Vs) % This loop runs 6 times (EDITED. I mistakently said 5 times before)
io_V1_mat = repmat(io(:, vsPtr), [1,points])';
subplot(3, 2, vsPtr)
cm = colormap(parula(points));
srf = surf(io_V1_mat,RL_mat, VL(:,:,vsPtr) ); % do I need to insert a 4th argument with the cm that I need?
cb = colorbar;
set(cb, 'ylim', [min(min(VL(:,:, vsPtr))) max(max(VL(:,:,vsPtr)))]);
cb.Label.String = 'Load Resitance Node Voltage';
cb.Label.FontSize = 12;
view(70, 50)
grid on
grid minor
box on
axis tight
srf = gca;
srf.YScale = 'log';
srf.XScale = 'log';
srf.XLabel.String = 'Iout [A]';
srf.YLabel.String = 'RL [Ohms]';
srf.Title.String = sprintf('Vs = %0.1f V', Vs(vsPtr));
end
My question is:
How on earth can I assign the color range from the colobars to the colormap of each plot? (look at the correspondence I am referring to here: I want to assign the color gradient shown in the colorbar to the colormap from each surf plot).
I have tried every proposed solution here in Mathworks without success (pulling my hair here tbh)
Any ideas?

채택된 답변

Kevin Holly
Kevin Holly 2022년 9월 2일
io_V1_mat=linspace(1000,100000,10);
RL_mat=linspace(1000,1000000,10);
VL=[2000*rand(10,4) 5000*rand(10,6)];
surf(io_V1_mat,RL_mat, VL, VL )% The fourth input is your values that correspond with the color map
colorbar
caxis([0 2000])% You can also change the limits of your colormap.
  댓글 수: 3
Kevin Holly
Kevin Holly 2022년 9월 3일
Ah, I see what you mean. You can add 'FaceColor','interp' to your surf function. For more info, click here.
io_V1_mat=linspace(1000,100000,10);
RL_mat=linspace(1000,1000000,10);
VL=[2000*rand(10,4) 5000*rand(10,6)];
surf(io_V1_mat,RL_mat, VL, VL,'FaceColor','interp')% Add 'FaceColor','interp'
colorbar
caxis([0 4000])
Daniel Melendrez
Daniel Melendrez 2022년 9월 6일
Dear Kevin
My apologies for the late reply
You were absolutely right!
Adding:
'FaceColor', 'interp'
did the trick
I think this information is explained in the 'FaceColor' section from the surf help page, however, it wasn't so evident for me. Perhaps more examples of the use of this modifier are needed.
Final result:
Thanks for your kind help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by