Dynamic color for a plot
조회 수: 13 (최근 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!