plot() colors using colormap?

6 Ansichten (letzte 30 Tage)
Andrea
Andrea am 28 Apr. 2011
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?

Antworten (2)

Teja Muppirala
Teja Muppirala am 29 Apr. 2011
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 am 28 Apr. 2011
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 Kommentar
Andrea
Andrea am 28 Apr. 2011
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by