MATLAB: Histogram Data out of axes boundries

axesboundrieshistogram

As you can see on the attached image, the values of my histogram are getting out of the axes boundries. Is there a way to limit that?
This is the code I've used for this axes:
%... GUI Elements
axes_img2 = axes('Units','pixels','Position',[631,350,450,300]);
%... GUI Elements & Functions
function btn_histo_Callback (~,~)
Bild2 = imread(Bild1); % Gibt Bilddatei in einem array (x*y) zurueck
if size(Bild2, 3) > 1 % Fehlerbehebung für "MAP must be a m x 3 array." bzw. Bild ist kein RBG-Bild. Size, gibt die "Grösse" des Bildes züruck, siehe 127.
Bild2gray = rgb2gray(Bild2); % rbg2gray erzeugt einen graustufenbild 1x1 Matrix aus einer 1x3 Matrix (RGB), falls Graustufenbild gezeigt werden soll, entsprechendes Arg. in imshow(I) aendern
else
Bild2gray = Bild2;
end
axes(axes_img2);
imhist(Bild2gray); % Erzeugt einen Histogramm des Graubildes. Das Histogramm zeigt wo (bei Maxima) die Mehrzahl eines Graustufenwertes sich befindet und sagt somit aus, welcher Wert der Hintergrund hat.
% Dieser Wert wird für den Schwellwert T (Threshold value) gebraucht um zu entscheiden ab wann, die Pixel den Wert 1 oder 0 annehmen. Abhaegigkeit 0->256 zu 0->1 ????
end

Best Answer

Hi, you can use axis limits to extend the plot to the edges of the axes. Refer the code below.
%... GUI Elements
axes_img2 = axes('Units','pixels','Position',[631,350,450,300]);
%... GUI Elements & Functions
function btn_histo_Callback (~,~)
Bild2 = imread(Bild1);
if size(Bild2, 3) > 1
Bild2gray = rgb2gray(Bild2);
else
Bild2gray = Bild2;
end
axes(axes_img2);
imhist(Bild2gray); axis tight;
end
Hope this helps!
Related Question