How do I create a 2-D or 3-D line that changes colors along the data points?
3 views (last 30 days)
Show older comments
MathWorks Support Team
on 20 Jan 2010
Edited: MathWorks Support Team
on 3 Dec 2020
I would like to plot a 2-D or 3-D line plot so that the colors change as the amplitude along the axes increases.
I would like to know how to produce a 3-D plot that uses the colormap for shading.
Accepted Answer
MathWorks Support Team
on 7 Jul 2016
Edited: MathWorks Support Team
on 3 Dec 2020
The MATLAB function, "plot3c.m", mimics the MESH command in a creative way to make a 2-D or 3-D line plot. Similar to how the mesh plot uses the colormap for shading, the color of the line will change with respect to the value of the specified axis in the "plot3c.m".
You can find the file at the following location:
Here is an example that uses this function to create a 2-D line of discrete markers that changes color with it's amplitude:
t = linspace(0,5*pi,100);
y=sin(t);
plot3c(t,y,0*t,y);
view(2)
colorbar
Here is an example that creates a scatter plot:\n
t = linspace(0,2*pi,40);
x = sin(t);
y = cos(t);
z = t.*x.^2;
plot3c(x,y,z,t,'x');
Alternatively, you may be interested in the SCATTER or SCATTER3 command. These can create scatter plots with point of varying colors. See the documentation for more information on these commands.
In addition the following file at the Matlab file exchange:\n
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9519&objectType=file
also provides an alternative efficient plotting routine that calls the PLOT3 routine only once for each group of points that map to the same color.
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!