Dynamic color for a plot
14 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am a beginner so forgive my stupid questions.
I am trying to classify some IMU data. I want different movements with different colors. Instead of complicating things with my details, I will put this simply.
a = [ 1 ; 2 ]
b = { 'b-' ; 'g-' }
When try to plot,
plot(a,b)
or
plot(a,char(b))
I get this error
??? Error using ==> plot Error in color/linetype argument
The real code looks like
axesAcc_X = plot(Acc_X(:,1),char(colorVector{:,1}));
Both vectors are of same size and I have ensured that the color type matches the desired data inside the data vector.
Can someone please help me?
Avishek
0 个评论
回答(3 个)
Walter Roberson
2012-5-31
You cannot specify multiple colors (or line styles, or markers) when you use a single Y for plot, even when Y has multiple columns. The syntax only allows for one linespec for each Y argument, and only if you interleave them
plot(x1, y1, 'b-', x2, y2, 'g-')
If you use a property name / value pair such as 'linestyle', '-', then only the last one of those in the plot() call will be paid attention to, and it will apply to all of the values plotted.
The solution is to record the handles output by plot (note that they are not "axes" handles, they will be lineseries handles), and to set() the linestyle etc. properties for each as appropriate.
Or set the axes ColorOrder property before plotting.
The MATLAB File Exchange contribution "plt" is more flexible I understand.
2 个评论
Walter Roberson
2012-5-31
plot() cannot be used to change the color on a point-by-point basis. scatter() allows changing the color on a point-by-point basis, but scatter() does not draw connecting lines.
Image Analyst
2012-5-31
You have a 1D set of numbers: Acc_X(:,1). Are you trying to plot it in both blue and green somehow???? Can you explain further?
3 个评论
Walter Roberson
2012-5-31
What does the second dimension of Acc_X represent? Based on your comments to me, it sounds like it is not the scenario number, as you indicate you have different lengths for for each scenario.
If Acc_X(:,1) is the X acceleration for all of the scenarios together, then is there any marker (such as NaN) to indicate when one scenario ends and the next begins? Or is there a vector indicating the starting point of each scenario?
Stephen
2012-6-1
if you want to change a bunch of stuff with plot, you could do it like this:
mark=['^';'s','o','.','x']
for t=1:5
h(t)=plot(acc_X(t));
set(h(t),'Marker',mark(t),'color',[randi(5)/5 1-t/5 t/5])
end
or something similarly convoluted and overcomplicated
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!