필터 지우기
필터 지우기

How can one display multiple Heatmaps in one figure on the same scale?

조회 수: 33 (최근 30일)
Douglas Anderson
Douglas Anderson 2022년 5월 20일
댓글: Voss 2022년 5월 21일
Hello,
I have spectral data from three components for several events. I have a short routine to plot the spectra:
% heater1
% Get the spectra and frequencies
spectra = Calc_All;
freeks = 1:size(spectra,2);
% Pick events
picked_events = ident(selections_from_table);
%Choose the event labels to use (e.g., file_name)
event_labels = input_struc.file_name(picked_events);
The
figure('Name','Spectral Map','NumberTitle','off','MenuBar','none','ToolBar','none');
for compo = 1:3
subplot(1,3,compo)
this_spec = squeeze(spectra(compo,:,:));
hdl = heatmap(freeks,event_labels,this_spec');
end
If I plot this just as it is, I get the following:
where (I guess it's hard to see) the max levels on each one are different, and so is the shading.
I don't know if fixing a Ylim for each one will work, since that's not known beforehand. Is there a simple way around this? I didn't see an "Answer" here. heatmap() is quite involved!
Thanks!
Doug

채택된 답변

Voss
Voss 2022년 5월 20일
You can specify the ColorLimits of all three heatmaps after they are created.
Here's a demonstration with some random data:
for compo = 1:3
subplot(1,3,compo)
% 1st heatmap ranges between 1 and 2, 2nd is [2 3], 3rd is [3 4]
% in order to see the effect of using common ColorLimits
this_spec = compo+rand(5,10);
hdl(compo) = heatmap(1:5,1:10,this_spec');
end
if numel(hdl) > 1
c_lim = get(hdl,'ColorLimits');
c_lim = vertcat(c_lim{:});
c_lim = [min(c_lim(:,1)) max(c_lim(:,2))];
set(hdl,'ColorLimits',c_lim);
end
  댓글 수: 7
Douglas Anderson
Douglas Anderson 2022년 5월 21일
Great! Thank you again, this is a huge help (both for the project and in understanding).
Voss
Voss 2022년 5월 21일
You're welcome!
By the way, here's the documentation for changing properties of heatmaps:

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by