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

29 visualizaciones (últimos 30 días)
Connor Monaghan
Connor Monaghan el 7 de Abr. de 2021
Editada: the cyclist el 7 de Abr. de 2021
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?

Respuesta aceptada

the cyclist
the cyclist el 7 de Abr. de 2021
Editada: the cyclist el 7 de Abr. de 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.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by