[Matlab] Colors and Symbols for ploting in loops
Posted on Friday, March 23, 2012, 3:28 AM
Sometimes it is easier to use a loop to plot something rather than manually typing plot many times. The problem is that all of the lines will have the same color and all the symbols will be the same. This code easily applies color to plots in a loop.
clear;clc;close all
% example data to plot
for i = 1:8
x = 0:10;
y(:,i) = i*x.^2;
end
symbol = {'o','s','^','v','<','>','d','p'};
colors = [ 0 0 0
0.8 0 0
1 0 0
1 0.6 0
0 0.6 0
0 0 1
0 0 0.6
0.8 0 0.8
];
for i = 1:8
hold on
h = plot(x,y(:,i),'color',colors(i,:),'marker',symbol{i})
end
hold off
Also, My friend Steven has developed a neat code for using color maps to generate the colors for a plot. - http://scslin.blogspot.com/2011/09/matlab-plot-with-more-colors.html
Subscribe to:
Post Comments (Atom)
2 Response to "[Matlab] Colors and Symbols for ploting in loops"
Good one MIL! Thanks for the code.
Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
Matlab Training in Chennai
Leave A Reply