Creating equally spaced x axis on plot function
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jake keogh
el 11 de Feb. de 2021
Respondida: Adam Danz
el 12 de Feb. de 2021
Hi,
I am writing a function that adds 4 data sets onto one graph, each point from each data set corresponds to the same x value and I am trying to set these on the x-axis.
My function and what i have tried is shown below:
function [] = comp(team)
if team == 5
disp('You have chosen to compare all teams')
y1 = readtable('Arsenal.xlsx');
y1 = y1{:,4};
y2 = readtable('Liverpool.xlsx');
y2 = y2{:,4};
y3 = readtable('ManchesterUnited.xlsx');
y3 = y3{:,4};
y4 = readtable('Chelsea.xlsx');
y4 = y4{:,4};
x = (06:1:17)';
plot(x,y1,'gd',x,y2,'ro',x,y3,'k*',x,y4,'bx')
seasons={'06/07'; '07/08'; '08/09';'09/10';'10/11';'11/12';'12/13';'13/14';'14/15';'15/16';'16/17';'17/18'};
set(gca,'xticklabel',x)
xlabel('Season')
ylabel('Goals Scored')
legend('Arsenal','Liverpool','ManchesterUnited','Chelsea')
end
end
The X tick label does not use these values I have given and simply goes from 6 to 12.
Thanks in advance for any tips, and any ideas on how I could simplify this code would be appreciated.
1 comentario
Respuesta aceptada
Adam Danz
el 12 de Feb. de 2021
My guess
set(gca,'xticklabel',x)
should be
set(gca,'xtick',x)
If not, we need more info.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!