How to plot max, min and average over a histogram?
12 views (last 30 days)
Show older comments
carlos ruiz de mendoza
on 8 Mar 2020
Commented: carlos ruiz de mendoza
on 9 Mar 2020
I have the following code that plots me a histogram:
% 1st GRAPH
figure(2)
hold on
a = connected_sites(:,3);
n = histc(a,1:nr_BBU);
max1 = max(n); % Max. valor
min1 = min(n); % Min. valor
avg1 = mean(n); % Valor medio
std1 = std(n); % Desvi. estándar
bar(1:nr_BBU,n)
title('Histogram distribution pool')
plot(1:nr_BBU,max1,'r.' ,'MarkerSize',15) %
set(gca,'XTick',1:nr_BBU)
xlabel('BBU Pool ')
ylabel('Nº of RRHs Connected');
legend({'BBU', 'Max1'},'AutoUpdate','off', 'Location', 'northeast')
And I get the desired histogram with an indicator for maximum values, but I would like to plot over also the minimum values, and the average.
Unfortunately I am quite as plotting is concerned and I can't get it. Any hints? Maybe it would be better to over plot a boxplot indicating the min, max and average??? I also can't get it to work.

2 Comments
Adam Danz
on 8 Mar 2020
Hint:
Repeat this line but substitude the min and mean values for the max value within the line.
plot(1:nr_BBU, max1, 'r.' , 'MarkerSize', 15) %
% ^^^^ max value
Accepted Answer
Adam Danz
on 8 Mar 2020
Edited: Adam Danz
on 8 Mar 2020
(continuing from comment section under the question)
To show the min or mean, substitute those values in for the max value in the line below.
plot(1:nr_BBU, max1, 'r.' , 'MarkerSize', 15) %
% ^^^^ max value
How easy would it be to over plot a boxplot ?
A boxplot isn't what you're looking for. A boxplot shows the quartile ranges, not the max and min. You could, however, use a vertical errorbar.
data = randi(20,1,6);
bar(1:size(data,2), data, 'DisplayName', 'Data')
minData = min(data);
maxData = max(data);
meanData = mean(data);
hold on
errorbar(size(data,2)+1, meanData, meanData-minData, maxData-meanData, '-d', 'Vertical', ...
'LineWidth', 2, 'MarkerSize', 10, 'DisplayName', '[min, mean, max]')
legend()

or horizontal reference lines
data = randi(20,1,6);
bar(1:size(data,2), data, 'DisplayName', 'Data')
minData = min(data);
maxData = max(data);
meanData = mean(data);
yline(minData, 'k-', 'Minimum')
yline(maxData, 'k-', 'Maximum')
yline(meanData, 'k-', 'Mean')
ylim([0, maxData+2])

More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!