Dynamic color for a plot
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (3)
Walter Roberson
il 31 Mag 2012
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 Commenti
Walter Roberson
il 31 Mag 2012
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
il 31 Mag 2012
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 Commenti
Walter Roberson
il 31 Mag 2012
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
il 1 Giu 2012
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 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!