0

I have two vectors, one is ~10x larger than the other. I'm trying to represent both on a probability distribution function histogram where each vector has a different color, but the PDF applies to the entire dataset...

If I use histogram(data), the output is in counts which is appropriately proportional. However, if I specify PDF normalization as below, both are scaled to their individual normalizations.

How can I plot all data as one single PDF, but maintain the colors?

Here is mock code:

% sample data
dist1 = normrnd(-2,1, [1, 750]); % Inthws vector
dist2 = normrnd(2,1, [1, 12000]); % Pchws vector

% Create histogram with dist1 in red
hold on
histogram(dist1, 'Normalization', 'pdf')

% Create histogram with dist2 in blue
histogram(dist2, 'Normalization', 'pdf')

% Add legend and axis labels
legend('dist1', 'dist2')
xlabel('Data values')
ylabel('Frequency or count')
hold off
Andrew M
  • 119
  • 6
  • 1
    So you want to add the two histograms? Maybe draw them as a stacked bar chart? – Cris Luengo Apr 09 '23 at 16:56
  • first [`histcounts`](https://www.mathworks.com/help/matlab/ref/histcounts.html) on separate data, then `bar` them in same figure. – X Zhang Apr 10 '23 at 00:32
  • _each vector has a different color, but the PDF applies to the entire dataset_ So you want each histogram to be normalized to the full data set, so that the sum of thw two areas is 1? – Luis Mendo Apr 10 '23 at 18:34

0 Answers0