plot() colors using colormap?
조회 수: 7 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (2개)
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
댓글 수: 0
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Red에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!