Azzera filtri
Azzera filtri

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

33 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Voss
Voss il 20 Mag 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 Commenti
Douglas Anderson
Douglas Anderson il 21 Mag 2022
Great! Thank you again, this is a huge help (both for the project and in understanding).

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by