Set string labels for a plot with multiple lines

4 visualizaciones (últimos 30 días)
Osh
Osh el 19 de Abr. de 2016
Editada: Osh el 19 de Abr. de 2016
Hi,
I create a plot with 3 lines with xTickLabels set as follows:
A=[1 2 3 8]; B=[2 4 5 6];
C=[5 7 11 12];
xaxis = [1:4];
semilogy(xaxis,A,'o-',xaxis,B,'o-',xaxis,C,'o-')
xlabel={'sample1','sample2','sample3','sample4'};
set(gca,'xticklabel',xlabel)
I want to mark the 4 points on the xaxis with the strings sample1,sample2,sample3 and sample4.
The above code is not quite doing that. Any suggestions on how to fix this?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Abr. de 2016
Editada: Azzi Abdelmalek el 19 de Abr. de 2016
A=[1 2 3 8]; B=[2 4 5 6];
C=[5 7 11 12];
xaxis = [1:4];
semilogy(xaxis,A,'o-',xaxis,B,'o-',xaxis,C,'o-')
xlabel1={'sample1','sample2','sample3','sample4'};
xt=xlim
set(gca,'xtick',linspace(xt(1),xt(2),4))
set(gca,'xticklabel',xlabel1)
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 19 de Abr. de 2016
To generate xlabel1, you can use
xlabel1=genvarname(repmat({'sample'},1,4),'sample')
Osh
Osh el 19 de Abr. de 2016
Editada: Osh el 19 de Abr. de 2016
Thanks, this worked! Can you pls explain what happened in line to fix my problem?
set(gca,'xtick',linspace(xt(1),xt(2),4))?
What will happen if the plot is loglog?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by