Colormap and plot with nxn matrices

Hi,
I have got 2 matrices x and y. For each x(i,:) y(i,:) I have got an array z. Now I want to draw them color coded like in a scatter plot corresponding with z and I also also want to have a colorbar, which is linked to the according color. At the same moment I want to have a solid line connecting the points in one course x(i,:) y(i,:).

답변 (2개)

Kelly Kearney
Kelly Kearney 2011년 6월 23일

1 개 추천

You can use a patch to make a color-changing line:
x = rand(10,1);
y = rand(10,1);
z = rand(10,1);
hp = patch([x' NaN], [y' NaN], 0);
set(hp,'cdata', [z' NaN], 'edgecolor','interp','facecolor','none');
hold on;
scatter(x,y,20,z,'filled');

댓글 수: 2

betlor5
betlor5 2011년 6월 24일
Ok, but I still can't set the patch to a pre defined colormap or can I?
Kelly Kearney
Kelly Kearney 2011년 6월 24일
The patch will follow the same colormap as the scatter plot, and you can change both the colormap and color limits for the axis to be whatever you need it to be.

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

Walter Roberson
Walter Roberson 2011년 6월 22일

0 개 추천

for K = 1:size(x,1)
plot(x(K,:),y(K,:),'-'); %solid line, no marker
hold on
pointsize = 8; %adjust as needed
scatter(x(K,:),y(K,:),pointsize,z(K,:)); %color coded dots
end
colorbar

댓글 수: 3

betlor5
betlor5 2011년 6월 23일
But that wouldn't change the color of the solid line. It would still be the defailt color, wouldn't it?
Walter Roberson
Walter Roberson 2011년 6월 23일
Yup. You didn't say you wanted to color-code the line itself.
There is no way built in to MATLAB to have a "line" or "lineseries" object have more than one color, so you need to color each segment individually.
Please indicate what color you expect each segment on the line to be. What about the segments that go between z of different value?
betlor5
betlor5 2011년 6월 24일
I have got multiple lines expressed through the points in my matrices x and y. These lines are independent from each other. Therefor I want to draw each line in one color corresponding to the z value. Let's say I want to display the x(1,:), y(1,:) curve. This curve shall be plottet in the color of z(1). And the colors of z shall follow a colormap, for example jet.

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

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

질문:

2011년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by