creating a rainbow colour plot/trajectory

130 visualizaciones (últimos 30 días)
cgo
cgo el 5 de Mayo de 2020
Comentada: KSSV el 5 de Mayo de 2020
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.

Respuestas (2)

KSSV
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
cgo
cgo el 5 de Mayo de 2020
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 el 5 de Mayo de 2020
The code used a deafult colormap......you need to set your colormap....read about cmap

Iniciar sesión para comentar.


Mehmed Saad
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
  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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by