creating a rainbow colour plot/trajectory

조회 수: 170 (최근 30일)
cgo
cgo 2020년 5월 5일
댓글: KSSV 2020년 5월 5일
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.

답변 (2개)

KSSV
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
cgo
cgo 2020년 5월 5일
thank you for your response. the expectation i have is one ROYGBV spectrum (red start and violet end).
But the real plot I have is more than one spectrum. why is this?
KSSV
KSSV 2020년 5월 5일
The code used a deafult colormap......you need to set your colormap....read about cmap

댓글을 달려면 로그인하십시오.


Mehmed Saad
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
  1. when you pass RGB value all edges will be of same color
  2. when you pass 'flat' argument to EdgeColor, it will change Color after every Edge
  3. 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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by