Plot smooth lines from limit data with colormap and legend

A=rand(10,10);
hold on
for i = 1:size(A,2)
plot(A(:,i))
hold on
end
Hello I store my data in a matrix, and I want to plot each colomn, I want to plot them in the colormap like this one, from purple to yellow, and give each color a legend, like "point 1", "point 2"
Also I know this could be bias, but I only have limited data, 10 points, anyway to smooth (interpolation) the line from the 10 ponts?

Answers (1)

cmap = [ ...
13 8 135; ...
67 3 158; ...
106 0 168; ...
145 14 163; ...
177 42 144; ...
204 71 120; ...
225 100 98; ...
242 133 75; ...
252 166 54; ...
252 206 37; ...
240 249 33; ...
]/255;
N = size(cmap,1);
A = (N:-1:1)+rand(N,1);
hold on
for ii = 1:N
plot(A(:,ii),'Color',cmap(ii,:));
end
legend(sprintfc('Point %c',64+(1:N)))

4 Comments

Thanks, how to use current colormap even it is not purple and yellow, and how did you smooth the line?
To use the current colormap, get it from the axes (instead of specifying it in the code like I did above):
cmap = get(gca(),'Colormap'); % colormap of the current axes
Then use cmap as above to set the line colors.
I didn't do any line smoothing; that's just plots of random data with a different offset for each line so you can see them.
A = (N:-1:1)+rand(N,1);
@Voss Thanks, but I do want some interpolation between each point.

Sign in to comment.

Categories

Products

Release

R2022a

Tags

Asked:

on 8 Nov 2022

Commented:

on 9 Nov 2022

Community Treasure Hunt

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

Start Hunting!