![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/750199/image.png)
Combine LineStyleOrder and ColorOrder
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2021-9-26
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'
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/750199/image.png)
更多回答(1 个)
Adam Danz
2023-3-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!