Displaying Histograms with decreasing bar heigths
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
jrbbrt
el 17 de Jul. de 2018
Comentada: Steven Lord
el 18 de Jul. de 2018
Hello,
My data: is a 1000x1 duration array, which I'd like to display within histograms ... with decreasing bar heights.
What I did so far is following:
- I defined my categories
- I created individual histograms
- And displayed those within one figure
%Defining the time periods I'd like to visualize
a=({'03:00:00'}>data_inm);
b={'06:00:00'}>data_inm;
b1=b-a;
c={'12:00:00'}>data_inm;
c1=c-b;
C=categorical(a,[1],{'0-3'});
C1=categorical(b1,[1],{'3-6'});
C2=categorical(c1,[1],{'6-12'});
%Visualization
figure('Name','My Categories');
hold;
histogram(C,'Normalization','probability','BarWidth',0.5);
histogram(C1,'Normalization','probability','BarWidth',0.5);
histogram(C2,'Normalization','probability','BarWidth',0.5);
Besides having more than 3 categories, I guess the way I tried to solve my task so far is not too effective.
... do you have an idea on how to display my histograms with decreasing bar heights? Or on how I could realize a more effective code? I'd be glad to hear your ideas!
Best regards! And thanks a lot in advance!
0 comentarios
Respuesta aceptada
Steven Lord
el 17 de Jul. de 2018
It's not clear to me what you mean when you say "with decreasing bar heights".
Do you want the total area of the bin to be proportional to the number of elements in the bin, not just the height, so a wider bin is shorter than a narrow bin with the same number of elements? If so, you probably want to specify the 'countdensity' or 'pdf' values for the 'Normalization' parameter when you create your histogram.
x = randn(1, 1e4);
E = [-3 -2 -1 -0.5 -0.25 0 0.25 0.5 1 2 3];
figure
histogram(x, E);
figure
histogram(x, E, 'Normalization', 'countdensity');
figure
histogram(x, E, 'Normalization', 'pdf');
Do you mean that you want the bar corresponding to a bin with 2 elements to be less than one unit taller than a bin with 1 element?
figure
h = histogram(x);
ax = ancestor(h, 'axes');
% Compare the appearance of the histogram before and after this line
ax.YScale = 'log';
If neither of those are what you want, please explain in more detail. If there's a webpage that shows specifically what you're trying to achieve, a link to that page may be useful in helping us understand your goal.
2 comentarios
Steven Lord
el 18 de Jul. de 2018
Ah, okay, you want the bins in descending order of height. That's easy. Set the DisplayOrder property of the categorical histogram to 'descend'. The "Change Display Order" section on this documentation page shows how to do this.
Más respuestas (0)
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!