Creating a ledgend with multiple colors for one set of data

Hi, I have this code. It basically plots the signal in a scatter plot colored in one of three ways. The points are one color if the value is <40, another if it is in [40,100] and another if it is >100
I was wondering if there is a way to set up the legend for a figure to have 3 text strings and to choose the color the legend displays.
Right now it just displays as item on the legend, because it is only one data set. I tried making two other dummy data sets (just graphed like two points, ex:(-90,-90) out of the range of the graph, and that gives me 3 data sets that show up and can be labeled on the legend, but I cant figure out how to manually set the color they should be. Is there a way to accomplish this? Any help would be great!
pointsize = 8;
[counts, ccode] = histc(signal,[-inf, 40, 100, inf])
scatter3(x,y,signal,pointsize,ccode(:));
colormap([1 0 0;0 1 0; 0 0 1]);

Answers (1)

It sounds reasonable to me that you can split your data points into three sets. It's relatively easy to split them apart based on the value. Then you have three sets of data and the legend will automatically match them.

Categories

Asked:

on 9 Aug 2011

Community Treasure Hunt

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

Start Hunting!