How can one display multiple Heatmaps in one figure on the same scale?
32 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Voss
on 20 May 2022
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 Comments
Voss
on 21 May 2022
You're welcome!
By the way, here's the documentation for changing properties of heatmaps:
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!