Combine LineStyleOrder and ColorOrder
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
EYKL
el 26 de Sept. de 2021
Respondida: Adam Danz
el 17 de Mzo. de 2023
Hello all,
I have a dataset which I want to plot by looping through a specific set of colours and linestyles at the same time. My problem is that while the colours are looping through, the linestyles do not. Does anyone have an idea of what I'm doing wrong?
y2 = randi([10 50],14,12);
set(gcf,'DefaultAxesColorOrder',[0,0,1; ...
0,0.7,0.3; ...
0.5,0,1; ...
0,0,0; ...
0.6,0.6,0.6; ...
0,0,0; ...
0,0.75,0.75; ...
0.9,0.4,0; ...
0.9,0,0.1; ...
1,0.6,0; ...
0.3,1,0.3], ...
'DefaultAxesLineStyleOrder',{'-o','-','-.','-x','-+','--+','--','-.','-+','-o','-o'});
ax = gca;
for i = 1:size(y2,2)
plot(x,y2(:,2:end));
ax.LineStyleOrderIndex = ax.ColorOrderIndex;
end
0 comentarios
Respuesta aceptada
Image Analyst
el 26 de Sept. de 2021
If that didn't work then perhaps try it like this instead.
y2 = randi([10 50],11,11);
x = 1 : length(y2);
myColors = [0,0,1; ...
0,0.7,0.3; ...
0.5,0,1; ...
0,0,0; ...
0.6,0.6,0.6; ...
0,0,0; ...
0,0.75,0.75; ...
0.9,0.4,0; ...
0.9,0,0.1; ...
1,0.6,0; ...
0.3,1,0.3];
lineStyles = {'-','-','-','-','-','--','--','-','-','-','-'};
markerStyles = {'o','x','.','x','+','+','.','.','+','o','o'};
ax = gca;
for k = 1:size(y2,2)
thisColor = myColors(k, :)
thisLineStyle = lineStyles{k};
thisMarkerStyle = markerStyles{k};
plot(x,y2(k, :), 'Color', thisColor, ...
'LineStyle', thisLineStyle, ...
'Marker', thisMarkerStyle, ...
'LineWidth', 3, 'MarkerSize', 18);
hold on;
end
g = gcf;
g.WindowState = 'maximized'
Más respuestas (1)
Adam Danz
el 17 de Mzo. de 2023
Starting in MATLAB R2023a you can cycle through LineStyleOrder and ColorOrder together by setting LineStyleCyclingMethod to 'withcolor'.
Demo
styles = {'-','-o', '-^'};
colors = [1 0 0; 0 0 1; 0 1 0];
ax = axes();
ax.LineStyleOrder = styles;
ax.ColorOrder = colors;
ax.LineStyleCyclingMethod = 'withcolor';
hold on
plot(0:.1:1, rand(1,11)+(1:6)')
legend
0 comentarios
Ver también
Categorías
Más información sobre Subplots 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!