x=[0 0]
y=[0 1]
colorscheme=[1 0 0;0 0 1]
graph=plot(x,y,'o')
set(gcf,'DefaultAxesColorOrder',colorscheme)
axis([0 100 0 200])
for i=1:100
x=[i i]
y=[i i+20]
set(graph,'xdata',x,'ydata',y)
drawnow
end
Thanks
Color order is not used when you are updating the position of an
existing graphics object: the existing object color is used.
If you want to change the color of an existing object, write the code
yourself. For example,
thiscoloridx = 1 + mod(i,size(colorscheme,1));
set(graph, 'xdata', x, 'ydata', y, 'color', colorscheme(thiscoloridx,:));
prop_name(1)={'MarkerFaceColor'}
prop_values(1,1)={'r'}
prop_values(2,1)={'b'}
prop_values(3,1)={'k'}
prop_values(4,1)={'y'}
h=plot([0 0 0 0;1 1 1 1],[1 4 3 2;1 2 4 3],'o')
set(h,prop_name,prop_values)
and compare it to this:
prop_name(1)={'MarkerFaceColor'}
prop_values(1,1)={'r'}
prop_values(2,1)={'b'}
prop_values(3,1)={'k'}
prop_values(4,1)={'y'}
h=plot([0 0 0 0],[1 4 3 2],'o')
set(h,prop_name,prop_values)
??? Error using ==> set
Value cell array handle dimension must match handle vector length.
Error in ==> graphcolorstest at 7
set(h,prop_name,prop_values)
Why is it that in the first example, there are four handles, each having two markers, while in the second there is only one handle?
Thanks
When plot() is handled a row matrix for X or Y, it converts it to a column
matrix, after which: plot() creates one line or lineseries object for each
column of Y.
[1 4 3 2;1 2 4 3]
has 4 columns for Y so plot() creates 4 lineseries objects.
[1 4 3 2] is a row vector so it is treated as the column vector [1;4;3;2]; Y
then has a single column so plot() creates a single lineseries object.
I see. Does this mean that it is impossible to create a plot with the number of handles equal to the number of plot points(except when there is a single point)? As:
plot([0 ;0],[1; 4],'o')
has only one handle.
No, it just means that plot() is not the tool to do that with.
If you are wanting to create a plot with one handle per point-pair, then each
point-pair would only cover one point, and there would be no joining of
points. In that case you might as well use scatter(), which allows you to
specify the color of each point, and you can change the color of points
afterwards by changing the CData property of the scattergroup series object.
If for some reason one handle per point-pair is important, line() the handles
in to existence one by one, such as via
h = arrayfun(@line, X, Y);
Add a row of NaNs to your data; they will force plot to treat each column as a separate object.
x=[0 0];
y=[0 1];
x = [x; nan(size(x))];
y = [y; nan(size(y))];
h = plot(x,y,'o');
col = {'r';'b'};
set(h, {'color'}, col);