creating a rainbow colour plot/trajectory
134 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
KSSV
2020-5-5
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 个评论
KSSV
2020-5-5
The code used a deafult colormap......you need to set your colormap....read about cmap
Mehmed Saad
2020-5-5
编辑:Mehmed Saad
2020-5-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!