Effacer les filtres
Effacer les filtres

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

24 vues (au cours des 30 derniers jours)
Douglas Anderson
Douglas Anderson le 20 Mai 2022
Commenté : Voss le 21 Mai 2022
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

Réponse acceptée

Voss
Voss le 20 Mai 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 commentaires
Douglas Anderson
Douglas Anderson le 21 Mai 2022
Great! Thank you again, this is a huge help (both for the project and in understanding).
Voss
Voss le 21 Mai 2022
You're welcome!
By the way, here's the documentation for changing properties of heatmaps:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by