How can I set different colors for different lines in a plot?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a vector of values named result, that indicates the color intensity of each pixel on the same vertical line on a image. I want tp plot it now with a colorbar. For the colorbar I defined the colors needed in the matrix colors. I used scatter to plot each point of result with its corresponding color and I connected all point using line().
That works well. Now I want to draw vertical line for each point and each line has to have the color of the corresponding point.
How can I do it?
Here is my code:
%defining the colors
image = imread('color_deg.jpg'); % image containing all colors needed
size_image = size(image);
ln = size_image(1);
colors = zeros(ln, 3);
% set all color values
for i=1:ln
vector = squeeze(image(i,10,:));
colors(i,:) = vector;
end
x = 1:1:size_result(2); %vector who has the lenght of the y-axis [1 2 3 ... s(2)]
ss = 50;
Color1 = colors/255;
fig = figure
colormap(Color1);
h=scatter(x,result,ss,result,'filled')
line(x,result) %connect all points
%draw vertical lines
for i=1:s(2)
line([i i],[0 result(i)])
end
colorbar
caxis([0 170]);
Here is an example of what my program can do now. I just want to set the colors for the vertical lines

0 commentaires
Réponses (1)
Kevin Phung
le 31 Jan 2019
Example:
a = line(x,y) % a is the handle to my line object
a.Color = [1 0 0] %red
%or you can do:
set(a,'Color',[1 0 0])
1 commentaire
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!