MATLAB >> scatter plot legend marker color

by Ben » Wed, 09 May 2007 13:26:22 GMT

Hi,

I seem to have come across this problem before, but have forgotten the
solution.

I have a scatterplot,

scatter(X1,Y1,50,Z1), hold on
scatter(X2,Y2,50,Z2), hold on
scatter(X3,Y3,50,Z3), hold off
legend('a','b','c')

the color of the markers in the legend are some light green color, I'd
rather have them be black.
I've looked at the legend properties, and found the Children, but I
see nothing about 'marker', 'facecolor', etc. Maybe I'm looking in
the wrong spot? (Aside: I really wish I could use something like
"grep" on matlab output).

Thanks!


MATLAB >> scatter plot legend marker color

by Yair Altman » Fri, 11 May 2007 17:33:14 GMT


hMarkers = findobj(hLegend,'type','patch');
set(hMarkers, 'MarkerEdgeColor','k', 'MarkerFaceColor','k');

Yair Altman

MATLAB >> scatter plot legend marker color

by Ben » Sat, 12 May 2007 12:17:10 GMT

I always forget about findobj. Thanks!

Similar Threads

1. colored markers in plot; cycling though colors

I'm adding points from different experiments to a plot and I would like to color them differently for each experiment.  The problem is that the number of experiments varies.  Therefore I need to make a color table that has n different colors, where n is the number of experiments.  I realize that I can assign a color in a plot by using, e,.g:
plot( ...,'markerfacecolor',[a b c])

and my question is how do I vary a,b,c so that I get a (rainbow) spectrum of colors.  

I tried:

for i=1:n
plot( [data from experiment], markerfacecolor',[1 1 1]/i)

and this resulted in shades of gray, which is difficult to view if there are more than 3-4 experiments. 

2. marker size in scatter plot - MATLAB

3. Marker/line attributes in legend vs. corresponding plot

On a plot with a legend, how can I get the markers in the legend to be a different size from the one in the plots that the legend is pointing to?   I want to do this since my plot markers are small due to the large amount of data, but then they don't show up very well in the legend.

Example code:
x=[1:1:10];
figure; 
hplot = plot(x,x,'.k');
h_for_legend = hplot;
set(hplot,'MarkerSize',2);   % small size marker
set(h_for_legend,'MarkerSize',12);   % attempt to get larger marker for legend
legend_string = 'my data';
legend(h_for_legend,legend_string);

I was hoping that the markers on the plot (handle hplot) would be size 2, and the marker in the legend (handle h_for_legend) would be size 12 so it would be visible.  A single size 2 marker in the legend is too small.     But the datapoints in the plot inheirit the marker size that I gave the legend (12).    How can I get them to be different in the plot vs. the legend (and change other attributes as well if I want)?

Thanks very much.

4. multiple legend and marker in plot - MATLAB

5. Legends to multiple scatter plots

Hi. Does anyone know how to put separate legends to multiple scatter plots? 

e.g. 
x=1:10;
y=11:20;
z=-y;

hold on;
scatter(x,y,'or')
scatter(x,z,'+b')
legend('y-name','z-name')
hold off 

This example incorrectly puts two legends 'y-name' and 'z-name' to one series y. 

Thanks a lot.

6. legends to scatter plots - MATLAB

7. Legend in scatter plot

Hi all,

I'm making a bubble plot using the scatter function in Matlab to show
the density of fish schools in a map of lat and long coordinates.
That is, the more dense the fish school, the larger the circle on the
scatter plot.

I can't figure out how to get a legend on the graph that shows what
the different sized circles represent.  When I add the legend, it has
all the circles as being the same size.

Any ideas?

Thanks!

8. Marker face colors in a log-log plot? - MATLAB