Plotting lines in subsequent color order, line marker and line style.
6 views (last 30 days)
Show older comments
Hi, I am selecting different R1.csv, R2.csv, R3.csv and R# in increasing number of files and the way I have them
set up now is that the first one that meets i==I_file prints it in red and the rest of selected
R#.csv Files are printed in black. However I want to create a loop that each file is printed in
a different line color. I've tried doing here something below but it does not work.
Can you suggest? Can the 'colororder' function work out for something like this?
do I need to define color everytime? Can the lines be on a loop as only 4 linestyles exist?
fileList = 1:length(fileNums);
%symbolList = ['o', 'x', 's', 'd','.', '^', 'v', '>', '<', '*','p', 'h','+'];
symbolList = [ 'o', '+', '*', '.', 'x', '_', '|', 's', 'd', '^', 'v', '>', '<', 'p', 'h', 'none'];
%colorList= [ [0, 0, 1], [0, 0.5, 0], [0, 0.4470, 0.7410], [0, 0.75, 0.75], [0.75, 0, 0.75], [0.75, 0.75, 0], [0.25, 0.25, 0.25] ];
colorList = ['#F00','#F80','#FF0','#0B0','#00F','#50F','#A0F'];
lineList = ['-', '--', ':', '-.'];
figure(3);
ax1 = gca;
ax1.Units = 'normalized';
for j=1:length(fileList)
i = fileList(j);
if i==I_file %NOTE: TO GET RID OF LINES, DELETE THE DASH in 'r%s-' etc.
%symbol = sprintf('r%s-', symbolList(mod(j-1,length(symbolList))+1));
symbol = sprintf('r%s%s', symbolList(mod(j-1,length(symbolList))+1), lineList(mod(j-1,length(lineList))+1) );
p=plot(I_u_std(:,i), z/z_of_V_max, symbol, 'LineWidth', 1);
p.DisplayName = sprintf('x/b=%3.3g', x_b(fileNums(i)));
elseif ~hideOtherXoverBs
%symbol = sprintf('k%s-', symbolList(mod(j-1,length(symbolList))+1));
symbol = sprintf('%s%s%s',colorList(mod(j-1,length(colorList))+1), symbolList(mod(j-1,length(symbolList))+1), lineList(mod(j-1,length(lineList))+1) );
p=plot(I_u_std(:,i), z/z_of_V_max, symbol, 'LineWidth', 0.1);
p.DisplayName = sprintf('x/b=%3.3g', x_b(fileNums(i)));
end %if
hold on;
end %for i
0 Comments
Accepted Answer
Voss
on 21 Dec 2021
Edited: Voss
on 21 Dec 2021
symbolList = [ 'o', '+', '*', '.', 'x', '_', '|', 's', 'd', '^', 'v', '>', '<', 'p', 'h', 'none'];
symbolList = 'o+*.x_|sd^v><phnone';
Those two lines do the same thing. That's not what you want. You want a cell array (because the symbols can be of different length because of the 'none'):
symbolList = { 'o', '+', '*', '.', 'x', '_', '|', 's', 'd', '^', 'v', '>', '<', 'p', 'h', 'none'};
Then access the jth element of symbolList with {}:
symbolList{mod(j-1,length(symbolList))+1}
Similarly for lineList for the same reason.
For colorList you can use a cell array of 1-by-3 numeric vectors, or you can use a 2d (n-by-3) numeric array:
colorList= [ 0, 0, 1; 0, 0.5, 0; 0, 0.4470, 0.7410; 0, 0.75, 0.75; 0.75, 0, 0.75; 0.75, 0.75, 0; 0.25, 0.25, 0.25 ];
Then the jth color will be the jth row of colorList:
colorList(mod(j-1,size(colorList,1))+1,:)
But, yes, you can use ColorOrder for the colors as well. If you use ColorOrder, you would not specify the line colors when you create the lines.
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!