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'
추가 답변 (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!