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!