필터 지우기
필터 지우기

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

조회 수: 3 (최근 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?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by