How to have a x-axis with repeating values (non-unique)
29 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
the cyclist
on 7 Apr 2021
Edited: the cyclist
on 7 Apr 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!