Home Matlab heatmap: Making a uniform colorscale for all subplots

# Matlab heatmap: Making a uniform colorscale for all subplots

Aiskya
1#
Aiskya Published in 2017-12-06 20:52:56Z
 I have 4 different dataset A,B,C,Dto generate 4 heatmaps in a subplot xvalues = {'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'}; yvalues = {'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16'}; subplot(2,2,1) HA = heatmap(xvalues,yvalues,A); HA.Title = 'A'; HA.XLabel = 'area'; HA.YLabel = 'area'; subplot(2,2,2) HB = heatmap(xvalues,yvalues,B); HB.Title = 'B'; HB.XLabel = 'area'; HB.YLabel = 'area'; subplot(2,2,3) HC = heatmap(xvalues,yvalues,C); HC.Title = 'C'; HC.XLabel = 'area'; HC.YLabel = 'area'; subplot(2,2,4) HD = heatmap(xvalues,yvalues,D); HD.Title = 'D'; HD.XLabel = 'area'; HD.YLabel = 'area';  Since each dataset has a different max and min value, the heatmap used the corresponding min and max values of each dataset for its color scale, so all 4 plots looked similar to each other. Is there a way to make a color scale so that it's uniformly used across all subplots? (will be easier to see the differences between the subplots)
gnovice
2#
 You first want to get the minimum and maximum values across all of the data sets, then use these to set the 'ColorLimits' property of each heatmap: minValue = min([A(:); B(:); C(:); D(:)]); maxValue = max([A(:); B(:); C(:); D(:)]); HA.ColorLimits = [minValue maxValue]; HB.ColorLimits = [minValue maxValue]; HC.ColorLimits = [minValue maxValue]; HD.ColorLimits = [minValue maxValue];  You could also use the caxis function (as you typically would for other plots), although you have to target each heatmap object since they each have their own colormap: caxis(HA, [minValue maxValue]); caxis(HB, [minValue maxValue]); caxis(HC, [minValue maxValue]); caxis(HD, [minValue maxValue]);