How can I set different colors for different lines in a plot?

1 回表示 (過去 30 日間)
Ouael Chkoundali
Ouael Chkoundali 2019 年 1 月 31 日
編集済み: Ouael Chkoundali 2019 年 1 月 31 日
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
Unbenannt.png

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 1 月 31 日
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 件のコメント
Ouael Chkoundali
Ouael Chkoundali 2019 年 1 月 31 日
編集済み: Ouael Chkoundali 2019 年 1 月 31 日
Thanks for your answer Kevin. But the color that I need is saved in the matrix Color1. The problem is that I can't kwon from wich line of the matrix it is. Is there any possibility to get the color of the points from the scatter plot or from the colorbar?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by