How can I set different colors for different lines in a plot?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Kevin Phung
am 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 Kommentar
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!