필터 지우기
필터 지우기

Combine LineStyleOrder and ColorOrder?!?

조회 수: 29 (최근 30일)
jan mischke
jan mischke 2015년 11월 23일
편집: Adam Danz 2023년 3월 17일
Can you combine LineStyleOrder and ColorOrder? I am plotting several plots in one subplot with semilogx and I want to change the color AND the LineStyle for every plot. Is that possible or do I have go through the Colors first?

채택된 답변

Mike Garrity
Mike Garrity 2015년 11월 23일
편집: Adam Danz 2023년 3월 17일
Update
Starting in MATLAB R2023a you can cycle through LineStyleOrder and ColorOrder together by setting LineStyleCyclingMethod to 'withcolor'. See this answer for a demo.
Prior to R2023a
You mean that you want to lop through them together, right? The way they actually work is to go through all of the entries in the ColorOrder, increment the LineStyleOrder, and then go through the ColorOrder again.
You can see it in this example:
set(gcf,'DefaultAxesColorOrder',[1 0 0; ...
0 1 0; ...
0 0 1], ...
'DefaultAxesLineStyleOrder',{'-','--o',':s'})
plot(magic(9))
legend show
As you can see, the first three plots are the three entries in the ColorOrder (red, green, blue) combined with the first entry in the LineStyleOrder ('-'). Next we get the three colors again with the second entry in the LineStyleOrder ('--o'). Then the three colors again with the third entry in the LineStyleOrder (':s'). If you were to continue, it would start over at the beginning.
If you wanted to increment them together, you'd have to manage it yourself. That would look something like this:
set(gcf,'DefaultAxesColorOrder',[1 0 0; ...
0 1 0; ...
0 0 1], ...
'DefaultAxesLineStyleOrder',{'-','--o',':s'})
ax = gca;
m = magic(9);
hold on
for i=1:9
plot(m(i,:))
ax.LineStyleOrderIndex = ax.ColorOrderIndex;
end
legend show

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 11월 23일
편집: Geoff Hayes 2015년 11월 23일
Jan - I don't see any reason why you can't combine the two for (example) the current axes (gca) as
set(gca, 'ColorOrder', myColours, 'LineStyleOrder', myLineStyleOrders);
where myColours and myLineStyleOrders describe the colours and line styles that you wish to display (see axes properties on how to specify the values for each of these properties.
  댓글 수: 1
Andre
Andre 2021년 1월 15일
In this case, the line style will only change after an entire cycle of color order is completed.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by