plot() colors using colormap?

조회 수: 7 (최근 30일)
Andrea
Andrea 2011년 4월 28일
Is there any way to associate a plot with a colormap?
To be more specific, right now I am attempting to plot a number of wireless links and I would like to represent the signal strength on each link using a color. However, I would like to take advantage of Matlab's interactive colormap shift functionality while I'm looking at the plot so that I can focus on small differences over certain signal strength ranges.
Right now, I'm drawing the links using:
colors = colormap;
plot([startPoint_x endPoint_x], [startPoint_y endPoint_y], '-', 'Color', colors(signalStrength,:));
colorbar;
(You can assume that signalStrength is discretized and ranges from 1 to length(colormap)). But of course the finished graph doesn't recognize that I'm attempting to use a colormap and the colorbar isn't associated with the colors in the figure.
I realize I could just do image(signalStrength) but then I lose the ability to see where the links are located, geographically, which is vital for me.
Help?

답변 (2개)

Teja Muppirala
Teja Muppirala 2011년 4월 29일
Maybe you could use patch objects to create the lines.
colordef(figure,'black');
hold all
startPoint_x = randn(1,10);
endPoint_x = randn(1,10);
startPoint_y = randn(1,10);
endPoint_y = randn(1,10);
signalStrength = ceil(64*rand(1,10));
for n = 1:10
h(n) = patch([startPoint_x(n) endPoint_x(n)],...
[startPoint_y(n) endPoint_y(n)],signalStrength(n)*[1 1],'edgecolor','flat','linewidth',3);
end
colorbar;
pause(1);
colormap hot
pause(1);
colormap summer
pause(1);
colormap cool

Walter Roberson
Walter Roberson 2011년 4월 28일
Line plots cannot use indexed colors for the lines.
Perhaps you could use image() with an AlphaData property that was transparent (Alpha 0) except along the lines you wish to define; then any image you would have underneath would show through except where the lines were.
  댓글 수: 1
Andrea
Andrea 2011년 4월 28일
Darn.
I guess I will try to use image() but is there any way to draw a line in an image just by specifying its endpoints? As opposed to having to manually generate matrices that visually approximate a line, e.g by creating
0.0 1.0 0.5
1.0 0.0 0.5
0.0 0.0 0.5
to mimic a diagonal line at maximum strength superimposed on a vertical line at half strength.

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

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by