Question

I have some problems with figures in Matlab. I divided my bar plot into two figures since I have totally 171 bars. I took the first half of the data at first (figure 1) and then the second half (figure 2). But then I got a problem with Xticks. Now both start from zero, but I would want the second half (figure 2) to be from 86 to 171 (or with intervals of 10 so that they are from 80 to 180, for instance). I tried set(gca, ‘XLim’, [86 171] to the second figure, but what happened was that bars in that figure ended up outside the figure, which I hadn’t thought before... Any hints how to solve the problem with the Xticks/dividing the figure?

I also have another question about Xticks! I would want to move them downwards in the figure, since I have added text (or actually other numbers which correspond to different bars) right above every bar. I made the figures to fit the whole screen by “set(gcf, 'Position', get(0,'Screensize'));”, but Xticks should be moved downwards so that Xticks and and other numbers are not on top of each other. I would like to learn how to solve these problems, but it seems like I need help from someone who has more experience!

Was it helpful?

Solution

The x ticks are specified by the X argument to bar().

n = 171;

x = randi(20, n);

subplot(2,1,1)
bar(1:85, x(1:85))
subplot(2,1,2)
bar(86:171, x(86:171))

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top