MATLAB: Combine LineStyleOrder and ColorOrder?!

colororderlinestyleorder

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?

Best Answer

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