Reputation:
I am plotting many polygons using the command fill
.
fill(X1,Y1,1)
fill(X2,Y2,2)
...
I want to set the edge color the same as the face color. What do I have to do for that?
I am plotting many polygons and I need to find a way to set the edgecolor same as the facecolor. Even the facecolors are not known to me. I have to use numbers, because I am plotting a data.Upvotes: 0
Views: 522
Reputation: 25232
I don't get what's wrong with the suggestion of CitizenInsane, but if you just want to save some code you could use a little helper function:
FillItLikeIWant = @(x,y,color) fill(x, y, color, 'EdgeColor',color)
FillItLikeIWant(x,y,'r')
Alternatively you can define all your "Styles" in advance, thats how I usually do it with line plots, in an array like this:
myStyles = {{'r','EdgeColor','r'};
{'b','EdgeColor','b'};
{'g','EdgeColor','g'}}
and then iterate through the styles:
for ii = 1:3
fill(x,y,myStyles{ii}{:}); hold on
end
Edit:
I don't know what the single number 1 or 2 in your example fill(X1,Y1,1)
is supposed to do, but maybe you want to create and use a colormap like this:
N = 500;
Cmap = colormap(jet(N));
Now use the helper function and every polygon gets another color of the Cmap
.
for ii = 1:500
h{ii} = FillItLikeIWant(x,y,Cmap(ii,:));
end
you can keep track of all colors just by the indices. Alternatively save the handles of every single polygon. So afterwards you can get the color of a polygon by its handle:
get(h{500},'FaceColor')
ans =
0.504 0 0
which is the same as:
Cmap(500,:)
ans =
0.504 0 0
Upvotes: 1
Reputation: 4855
Just set EdgeColor
property/value pair, with the same color as faces:
t = (1/16:1/8:1)'*2*pi;
x = sin(t);
y = cos(t);
fill(x, y, 'r', 'EdgeColor', 'r');
Sample code for drawing multiple polygons with different colors in a for loop (using current colormap):
function [] = foo()
%[
cmap = colormap; % Use some colormap to have different color for polygons
ccount = size(cmap, 1); % Number of elements in the colormap
figure; % Create a figure
hold on; % Avoids deleting previous polygons
pcount = 50; % number of polygons
for i = 1:pcount,
% Create randomly translated polygon
t = (1/16:1/8:1)'*2*pi;
x = 0.1*sin(t) + rand;
y = 0.1*cos(t) + rand;
% Select a color in the colormap
colorIndex = mod(i, ccount);
if (colorIndex == 0), colorIndex = ccount; end
colorValue = cmap(colorIndex, :);
% Draw the polygon
fill(x, y, colorValue, 'EdgeColor', colorValue);
end
%]
end
Upvotes: 1