Reputation: 2299
I would like to change the legend style of the following picture generated in Matlab:
x1=-5;
x2=5;
y1=-5;
y2=5;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
fill(x,y,'b')
legend('A')
As you can see the legend displays a blue rectangle. What I would like is a filled blue circle in place of the rectangle as if the picture was generated as a scatter plot. How can I obtain that?
Upvotes: 2
Views: 106
Reputation: 3071
@Bebs has a nice solution.
Another suggest is to change directly the legend icon:
[a,b] = legend('A');
b(2).Xdata = sin(-pi:0.1:pi)/10+0.4; % you can play with numbers to set size and location of circle
b(2).Ydata = cos(-pi:0.1:pi)/5+0.5;
Now you can set some other properties:
b(2).LineWidth = 1; % thicker line
b(2).FaceColor = [1 1 1]; % white fill
b(2).EdgeColor = [0 0 1]; % blue edge
Upvotes: 3
Reputation: 1550
I would suggest to add a fictive value with hold on; p = plot(NaN, NaN, 'b.', 'MarkerSize', 15);
then legend this specific "fake" plot with: legend(p, 'A');
x1=-5;
x2=5;
y1=-5;
y2=5;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
fill(x,y,'b');
hold on; p = plot(NaN, NaN, 'b.', 'MarkerSize', 15);
legend(p, 'A')
Upvotes: 3