Equal histogram distance in MATLAB

I have this histogram in MATLAB created using the command bar:

enter image description here

I was wondering if there is a way to get rid of empty spaces between 2478 and 2886 and between 4314 and 5130

If I can make the bars have an equal amount of space between them, that would be ideal.

+6
source share
2 answers

As described in the documentation bar,

bar(x,y)draws stripes at the locations indicated x.

which means this behavior is intended: each line is drawn in the exact position indicated x.

, categorical, x , . , MATLAB, x , x(i) x - i - , .

bar(categorical(x), y)

Categorical x-bar

+10

x .

[1, 2, 3, ..., 13]

:

x = [1886,2070,2274,2478,2886,3090,3294,3498,3702,3960,4110,4314,5130];
y = rand(1,13)*5 + 32;

bar( 1:numel(y), y );
set( gca, 'XTickLabel', x );

plot

+6

All Articles