How to plot max, min and average over a histogram?

6 visualizaciones (últimos 30 días)
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 comentarios
Adam Danz
Adam Danz el 8 de Mzo. de 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
carlos ruiz de mendoza
carlos ruiz de mendoza el 8 de Mzo. de 2020
Thank you so much!!! How easy would it be to over plot a boxplot ?

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 8 de Mzo. de 2020
Editada: Adam Danz el 8 de Mzo. de 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])

Más respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by