
Combine LineStyleOrder and ColorOrder
10 ビュー (過去 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 で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!