# How can I draw a filled circle?

1,306 views (last 30 days)
vatankhah on 13 Sep 2013
Commented: Image Analyst on 24 Mar 2021
I know the radius and the center coordinate of a circle
I want to fill this circle with black color
how can I do this?
abdalaziz alkassm on 17 Jul 2020
Using fill(x,y,'b')

Walter Roberson on 13 Sep 2013
Image Analyst on 24 Mar 2021
I don't believe viscircles() offers a 'filled' option yet to make the entire disc one solid filled color. That would be a good enhancement. I believe it only draws the perimeter.

Shahriar on 9 Nov 2013
Very simple. The following will draw a filled circle at (1,1) with red color. Change it as you wish.
plot(1, 1, '.r', 'MarkerSize',69)
##### 2 CommentsShowHide 1 older comment
Gavin Walch on 8 Nov 2019
Thank you! I found this solution to be the best(and simplest) solution for my need

Image Analyst on 13 Sep 2013
To create a 2D logical image of a solid circle (a disc), you can use code like this:
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
Image Analyst on 23 Jan 2020
If it's a gray scale image, just use the code above to create a binary image with all the circle(s) on it, then set everywhere in the binary image mask to whatever gray level you want:
grayImage(binaryImage) = 255; % Set to white.

Chad Greene on 20 Nov 2014
A few FEX submissions make it easy:
##### 2 CommentsShowHide 1 older comment
Image Analyst on 6 Feb 2021
Now there is a viscircles function built in to the Image Processing Toolbox
This can handle vectors of centers and radii, in addition to just one.

Edited: Walter Roberson on 10 Nov 2019
Simply, use the following command:
I = insertShape(I,'FilledCircle',[x y r],'color',[1 1 1],'LineWidth',5);
[x y] is the centre coordinates r is the radius
Note, you need Computer Vision Toolbox to run this command.
Walter Roberson on 10 Nov 2019
This is a good routine to use if you have a matrix that you want to draw a circle into. It is not, however, a good routine to draw a circle on the display.

vatankhah on 13 Sep 2013
Edited: vatankhah on 13 Sep 2013
thanks for the answer but I want just a simple command in matlab to fill a circle that is plotted with specified radius and center coordinate
Image Analyst on 13 Sep 2013
That's what rectangle() does, believe it or not. Look at the examples in the link Walter gave you.

vatankhah on 14 Sep 2013
thanks a lot for your help, it was useful

Anton on 24 Sep 2014
Edited: Walter Roberson on 10 Nov 2019
Use "area" command. Typically used to fill area under y=f(x) curve.
Using Rectangle command has 2 inconveniences: 1) They use figure axes, not the graph axes (see this submission for help http://www.mathworks.co.uk/matlabcentral/fileexchange/30347-sigplot/content/sigplot/sigplot/BasicFunctions/dsxy2figxy.m )
2) a consequence of 1 in fact: if you zoom or move the graph your circle will remain in "old" position and scale, which is annoying.
This is how you draw a filled circle of radius R at (x,y) in the axis of your graph using "area" command:
Ang = 0:0.01:2*pi; %angle from 0 to 2pi with increment of 0.01 rad. CircX=R*cos(Ang); CircY=R*sin(Ang);
h=area(X+CircX,Y+CircY);
set(h,'FaceColor',[.7 0 0]) %colour of your circle in RGB, [0 0 0] black; [1 1 1] white set(h,'LineStyle','none')
% unfortunately you have to remove the line: because circle is not a function strictly speaking. % "area" command tries to fill area below your function which leaves a line-artefact connecting your circle with X axis.
Walter Roberson on 10 Nov 2019
? rectangle() uses data units, which are axes relative. It does not use figure units.
annotation() uses figure units though.