MATLAB Answers

0

How to fix the values of different histograms 2D to have the same color reference?

Asked by Jose L. Santacruz on 10 Jan 2019
Latest activity Commented on by Image Analyst
on 11 Jan 2019
Hi, I'm trynig to plot several histograms and I'll like to see the difference between them. For that, Matlab fixes the colors based on the maximum value for each histogram, so despite of having different values (amplitude) between histograms the color of the highest and the lowest are the same. That makes it difficult to have an idea of the real difference between them, and makes it necessary to check the colorbar. In the images, I would like to have more intense colors for the first histogram and less intense for the second one, since the values are higher in the first one. How could I fix this?
Here is the code I'm using for the histograms:
string1 = 'HL vs MML at';
string2 = num2str(currentFreq);
ti = strcat (string1,{' '},string2,{' '},'Hz');
Xedges = [0 0:10:100 100];
Yedges = [0 0:10:100 100];
h = histogram2(A, B,Xedges,Yedges,'DisplayStyle','tile','ShowEmptyBins','on');
hcb=colorbar;
colorTitleHandle = get(hcb,'Title');
titleString = 'Number of ears';
set(colorTitleHandle ,'String',titleString);
ylabel('MML (dB)')
xlabel('Hearing Loss (dB HL)')
ask.png
Thanks a lot in advance

  0 Comments

Sign in to comment.

2 Answers

Answer by Image Analyst
on 11 Jan 2019

You can specify caxis() for each plot to be the same.
% First do one image.
% then call caxis():
caxis([0, 33]);
% Now make second image in second axes.
% And apply the same caxis limits.
caxis([0, 33]);

  1 Comment

Sign in to comment.


Answer by SHUBHAM GUPTA on 11 Jan 2019
Edited by SHUBHAM GUPTA on 11 Jan 2019

One way to do this is to use "colormapeditor". Type the following in command window :
colormapeditor
In the dialog box, you can change the limits of the Colorbar to be equal for both plots.
Note : Setting colormap limits to be the maximum of the two plots should work much better

  2 Comments

"Note : Setting colormap limits to be the maximum of the two plots should work much better"
To do this, you use caxis() like I showed in my Answer.

Sign in to comment.