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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by