how du I construct the following Horizontal graph?

How do you construct a similar graph in Matlab?
The graph is generated from a unit root test, where the shaded areas represents periods where the test statistic is greater than the cirtical values.

 Accepted Answer

This should get you started —
x = datetime(1980,1,1) : calmonths(1) : datetime(2013,12,31); % Create Vector
y = sort(randi(numel(x), 10, 6), 2) % Create 'Country' Matrix
y = 10×6
27 37 63 228 266 312 42 159 188 335 341 383 124 135 153 241 293 368 132 160 170 182 282 333 75 78 87 258 310 396 38 119 164 224 255 324 90 203 214 216 328 347 20 118 145 160 211 253 8 18 38 56 205 327 2 121 150 188 228 393
figure
for k1 = 1:size(y,1)
for k2 = 1:2:numel(y(k1,:))-1
idx = y(k1,k2:k2+1);
patch([x(idx) flip(x(idx))].', k1+[zeros(size(idx)) ones(size(idx))].', [1 1 1]*0.7, 'EdgeColor','none')
yline(k1+1,'-k')
yline(k1-1,'-k')
end
end
Ax = gca;
set(Ax, 'YTick',(1:size(y,1))+0.5, 'YTickLabel',compose('Country %3d',1:size(y,1)))
The ‘y’ matrix indexes into the ‘x’ vector to produce the patch regions. The nested loops appear to be the only option for the patch plots. See the documentation for the various functions and Axes Properties to change the plot appearance.
.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!