How to have a x-axis with repeating values (non-unique)

조회 수: 30 (최근 30일)
Connor Monaghan
Connor Monaghan 2021년 4월 7일
편집: the cyclist 2021년 4월 7일
I am having some issues trying to reporduce a plot in MatLab, I have seen this layout of plot many times.
As an example here is the plot in Excel:
As you see the x-axis is reapeting on itself between 4-9 three times. If it is any help, in Excel I use category labels for the x-axis.
Is something like this possible in MatLab?

채택된 답변

the cyclist
the cyclist 2021년 4월 7일
편집: the cyclist 2021년 4월 7일
I have not seen a plot of this style. It's a bit confusing to me. I'm curious what the color background regimes are. Training, testing, validation?
The solution will depend on whether the x data themselves repeat or not.
If the x values do not repeat, and you are just shifting regimes over, then you can just adjust the labels:
rng default
x = 4:21;
y = rand(size(x));
figure
plot(x,y)
set(gca,'XTick',x,'XTickLabel',4:9) % Note that the labels repeat, because there are not "enough" for the ticks
axis tight
I don't love this solution, because it breaks the correspondence between the label and the data. But maybe you need to do that.
If the data themselves repeat, you'll need to use a third variable to force the different regimes to not overlap. Then I think you'll still need the above labeling method.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by