cndkrt
cndkrt

Reputation: 79

How to change axis values in Matlab (imhist command)

%boat_image&histogram
subplot(1,2,1)
imshow(I01);
subplot(1,2,2)
imhist(I01);
saveas( gcf, 'boat_image&histogram', 'jpg' );

enter image description here I want to cover all y values. How can I change the axis values in terms of the covering maximum value?

after adding following commands, I recieved a different histogram below.

%boat_image&histogram
subplot(1,2,1)
imshow(I02);
subplot(1,2,2)
[cts,x] = imhist(I02);
stem(cts,x);
ylim([0,max(x)]);
saveas( gcf, 'boat_image&histogram_', 'jpg' );

enter image description here

after switch:

%boat_image&histogram
 subplot(1,2,1)
    imshow(I02);
    subplot(1,2,2)
    [x,cts] = imhist(I02);
    stem(x,cts);
    ylim([0,max(x)]);
    saveas( gcf, 'boat_image&histogram_', 'jpg' );

after correct switch :)

%boat_image&histogram
subplot(1,2,1)
imshow(I02);
subplot(1,2,2)
[cts,x] = imhist(I02);
stem(x,cts);
ylim([0,max(cts)]);
saveas( gcf, 'boat_image&histogram__', 'jpg' );

enter image description here

It was added;enter image description here

There is a big visual gap both first histogram and the last one.

Upvotes: 1

Views: 1514

Answers (1)

flawr
flawr

Reputation: 11628

You could probably use

ylim([0,max_val])

where max_val is the greatest y-value you want to have displayed.

You could even do that directly using

h = hist(your_data);
ylim([0,max(h)]);

Alternatively when using imhist you can use the stem command:

[cts,x] = imhist(img);
stem(x,cts);
ylim([0,max(cts)]);

Upvotes: 2

Related Questions