plot multiple lines with same sample size and apply colour string
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yuktha Andie Ravinthiran
le 17 Fév 2022
Commenté : William Rose
le 19 Fév 2022
p2 = 'filename.xlsx'
hold on
set(groot,'defaultLineLineWidth',1.5)
ex = xlsread(p2,'1','E2:E37');
ey = xlsread(p2,'1','C2:C361');
eplot = plot(ex,rescale(ey(1:36)),'r-.',ex,rescale(ey(37:72)),'color','#D95319',ex,ey(73:108),'color','#EDB120');
legend('1','2','3')
I can plot 2 lines but when I add the third, it says there is error using plot and error using matlab_graphs
When plotting, is there a way to specify plot ey in chunks of 36 and apply a rainbow colourstring to the lines plotted
0 commentaires
Réponse acceptée
William Rose
le 17 Fév 2022
Modifié(e) : William Rose
le 17 Fév 2022
Yes it is possible. Use the "hold on" command and write a for loop. Inside the ploop, plot successive sets for 36 points.
See below.
N=432;
x=rand(1,N); %create N data points
M=36;
P=floor(N/M); %number of loop passes to make
colors=[1,0,0; 1,.5,0; 1,1,0; .5,1,0; ...
0,1,0; 0,1,.5; 0,1,1; 0,.5,1;...
0,0,1; .5,0,1; 1,0,1; 1,0,.5]; %colors to use
figure;
hold on
for i=1:P
plot((i-1)*M+1:i*M,x((i-1)*M+1:i*M),'Color',colors(i,:));
end
Try it.
1 commentaire
William Rose
le 19 Fév 2022
I see now that you plotted your 36 point groups all versus the same x-axis values. To do this, change the "plot" line in the code above:
N=432;
x=rand(1,N); %create N data points
M=36;
P=floor(N/M); %number of loop passes to make
colors=[1,0,0; 1,.5,0; 1,1,0; .5,1,0; ...
0,1,0; 0,1,.5; 0,1,1; 0,.5,1;...
0,0,1; .5,0,1; 1,0,1; 1,0,.5]; %colors to use
figure;
hold on
for i=1:P
plot(1:M,x((i-1)*M+1:i*M),'Color',colors(i,:));
legstr{i}=sprintf('Run %d',i);
end
legend(legstr);
I added a legend line.
Good luck.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Bar Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!