creating a rainbow colour plot/trajectory
134 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I was reading this:
to create a rainbow coloured plot. I have data points X(:,1) and X(:,2) (Both x and y axis). I do not understand how to use the function in the link to create a trajectory with rainbow colours.
Please help.
0 comentarios
Respuestas (2)
KSSV
el 5 de Mayo de 2020
clc; clear all ;
x = 1:50 ;
y = rand(size(x)) ;
z = zeros(size(x)) ;
col = x; % This is the color, vary with x in this case.
surface([x;x],[y;y],[z;z],[col;col],...
'facecol','no',...
'edgecol','interp',...
'linew',2);
2 comentarios
KSSV
el 5 de Mayo de 2020
The code used a deafult colormap......you need to set your colormap....read about cmap
Mehmed Saad
el 5 de Mayo de 2020
Editada: Mehmed Saad
el 5 de Mayo de 2020
You can use surface or patch for that purpose but not plot
I am going to describe how to do it with patch
figure,plot(1:3,[1 -1 1],'r')
Now replace plot with patch (remember patch needs polygon Color)
figure,patch(1:3,[1 -1 1],'r')
So patch creates a patch between [1 -1 1] and join the the first and last point at the end (to complete the patch)
red is the facecolor (PolyGon Color) of patch we passed in the 3rd argument of the function. and black is by defailt EdgeColor of patch object.
To change EdgeColor we can
figure,plot(1:3,[1 -1 1],'r','EdgeColor','c')
Now if we just want to draw the line and not the area patch is covering
figure,patch(1:3,[1 -1 1],'r','FaceColor','None')
but it will still join the first and last element. In order to stop that, insert another element at the end and set its value to NaN
figure,patch(1:4,[1 -1 1 NaN],'r','FaceColor','None')
Now Patch EdgeColor has following options
- when you pass RGB value all edges will be of same color
- when you pass 'flat' argument to EdgeColor, it will change Color after every Edge
- when you pass 'interp' it will linearly interpolate betweeen two edges
For RGB
figure,patch(1:4,[1 -1 1 NaN],'r','EdgeColor','g')
For Flat, only two Colors 1:2 , 2:3 (there's also third color which is not visible because line is leading to NaN)
figure,patch(1:4,[1 -1 1 NaN],4:-1:1,'EdgeColor','flat')
figure,patch(1:4,[1 -1 1 NaN],4:-1:1,'EdgeColor','interp')
colormap('jet')
when you select interp for EdgeColor or FaceColor, then 3rd Argument (Polygon Color) should be change
0 comentarios
Ver también
Categorías
Más información sobre Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!