How to add velocity colourbar to graph
25 views (last 30 days)
Show older comments
Alexander Hamilton
on 26 Sep 2016
Commented: Massimo Zanetti
on 27 Sep 2016
Hey,
I have a 3D graph plotting the trajectory of a particle. My plot therefore provides the point to point position of the particle.
I was wondering if there was a method to add a color bar that represents the particle velocity at each position. I have the particle velocity at each position stored as vectors.
My plot is basically a curved line.Is there a way to use the colorbar command to enable the colour of the particle at each of the points to change correlating to the velocity?
Any help would be greatly appreciated :)
2 Comments
Massimo Zanetti
on 26 Sep 2016
What command are you using to plot the curved line? Are you using plot3?
Accepted Answer
Massimo Zanetti
on 26 Sep 2016
The plot3 function does not allow to map different colors. However, you can get around using SURFACE. Try this.
%3d coordinates of a curve
x = 0:.05:2*pi;
y = sin(x);
z = cos(x);
%color vector: a set of values that are mapped in the colorbar
col = rand(1,numel(x));
%plot the curve as a surface
surface([x;x],[y;y],[z;z],[col;col],...
'facecol','no',...
'edgecol','interp',...
'linew',2);
grid on; view([90,45,45]);
colorbar;
2 Comments
More Answers (1)
KSSV
on 26 Sep 2016
How about this?
N = 100 ;
% Take some positions
x = linspace(0,2*pi,N) ;
y = sin(x) ;
%%associate some random velcoity
v = rand(N,1) ;
hold on
plot(x,y,'r') ; % plot trajcetory
scatter(x,y,50,v,'filled') ; % velcoity as a scatter plot
colorbar
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!