How do I set the plot color and line style of several data sets using a cell array?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am plotting several sets of data on a single plot and would like to control the color and linestyle of each line using a cell array like this:
figure(1)
hold on
grid on
xlim([0 60])
colorVec = {'b', 'r', 'y', 'p', 'g', 'c'};
linVec = {'--', '-.','--', '-.','--', '-.'};
yyaxis left
plot(tvar,Ts1(:,:),'Color',colorVec{:},'LineStyle',linVec{:},'LineWidth',2,'MarkerSize',5)
hold off
However, the above code does not work and produces an error. Can anyone help me with the syntax of what I am trying to accomplish? Thank You in advance.
0 comentarios
Respuestas (1)
KSSV
el 23 de Abr. de 2018
figure(1)
hold on
grid on
xlim([0 60])
colorVec = {'b', 'r', 'y', 'm', 'g', 'c'};
linVec = {'--', '-.','--', '-.','--', '-.'};
yyaxis left
for i = 1:6
plot(tvar,Ts1(:,i),'Color',colorVec{i},'LineStyle',linVec{i},'LineWidth',2,'MarkerSize',5)
end
hold off
3 comentarios
Rebecca Tyson
el 19 de Dic. de 2018
Was this question ever solved? I'm trying to do the same thing...
Lana Piner
el 17 de Mayo de 2019
Not sure, if this helps and it has been a while, but if you set default colors ahead of time, you do not need to call them in the loop - they will be picked automagically in the order they are listed.
set(groot,'defaultAxesColorOrder',[1 0 0;0 1 0;0 0 1])
This is done any time before you hold figure and do the loop.
Ver también
Categorías
Más información sobre Interactive Control and Callbacks 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!