Histogram: 'Greater than' bin
Ältere Kommentare anzeigen
Simple question but I can't seem to find an answer: How do I add a bin to my histogram for the values outside of the visible range? Plotted automatically, the data below has values ranging from 0-200, the last 5 bins (100-200) have one point each. When I change the bin range to 0-100, those 5 bins are cut off. I want to take the points with values greater than the max(BinEdges) value, and have a bin labelled '>100' (populated dynamically as the bin edges are changed).
h=histogram(grains.area);
h.BinLimits=[0 100];
%Make range labels for bins
label = arrayfun(@(x,y) sprintf('%g - %g',x,y), ...
h.BinEdges(1:end-1), h.BinEdges(2:end), ...
'UniformOutput', false);
%label x axis with bin ranges
set(gca,'XTick',(h.BinEdges(1:end-1)+h.BinEdges(2:end))/2,...
'XTickLabel',label)
% get x position for bin count labels
xLblPos=h.BinEdges(1:end-1)+h.BinWidth/2;
%get y position
lift=max(h.Values)/20;
yLblPos=h.Values+lift;
%label each bar at top
cont=string(h.Values);
text(xLblPos,yLblPos,cont)
Akzeptierte Antwort
Weitere Antworten (1)
Jessica Hiscocks
am 26 Apr. 2018
Kategorien
Mehr zu Axis Labels finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!