# Draw Circle - Diameter, Radius, Arc and Segment Using Python Matplotlib Module

In this blog, we will plot point at origin then circle. After that we will plot diameter, radius, arc and segment(chord) using matplotlib library.

### Circle

A circle is a shape consisting of all points in a plane that are at a given distance from a given point, the centre; equivalently it is the curve traced out by a point that moves in a plane so that its distance from a given point is constant. The distance between any point of the circle and the centre is called the radius.

### Circumference

the distance around the circle.

### Centre

the point equidistant from all points on the circle.

### Diameter

Diameter a line segment whose endpoints lie on the circle and that passes through the centre; or the length of such a line segment. This is the largest distance between any two points on the circle.

The distance between any point of the circle and the centre is called the radius.

### Arc

any connected part of a circle. Specifying two end points of an arc and a center allows for two arcs that together make up a full circle.

### Chord

a line segment whose endpoints lie on the circle, thus dividing a circle into two segments.

## Import Modules

In [1]:
import matplotlib.pyplot as plt
import numpy as np
from numpy import sin, cos, pi, linspace


## Plot point at origin(0, 0)

In [2]:
#draw point at origin (0, 0)
plt.plot(0,0, color = 'red', marker = 'o')
plt.show()


### Add annotation and set xlim and ylim

In [3]:
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), fontsize=10)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


## Draw a circle

In [4]:
angles = linspace(0 * pi, 2 * pi, 100 )
print(angles)

[0.         0.06346652 0.12693304 0.19039955 0.25386607 0.31733259
0.38079911 0.44426563 0.50773215 0.57119866 0.63466518 0.6981317
0.76159822 0.82506474 0.88853126 0.95199777 1.01546429 1.07893081
1.14239733 1.20586385 1.26933037 1.33279688 1.3962634  1.45972992
1.52319644 1.58666296 1.65012947 1.71359599 1.77706251 1.84052903
1.90399555 1.96746207 2.03092858 2.0943951  2.15786162 2.22132814
2.28479466 2.34826118 2.41172769 2.47519421 2.53866073 2.60212725
2.66559377 2.72906028 2.7925268  2.85599332 2.91945984 2.98292636
3.04639288 3.10985939 3.17332591 3.23679243 3.30025895 3.36372547
3.42719199 3.4906585  3.55412502 3.61759154 3.68105806 3.74452458
3.8079911  3.87145761 3.93492413 3.99839065 4.06185717 4.12532369
4.1887902  4.25225672 4.31572324 4.37918976 4.44265628 4.5061228
4.56958931 4.63305583 4.69652235 4.75998887 4.82345539 4.88692191
4.95038842 5.01385494 5.07732146 5.14078798 5.2042545  5.26772102
5.33118753 5.39465405 5.45812057 5.52158709 5.58505361 5.64852012
5.71198664 5.77545316 5.83891968 5.9023862  5.96585272 6.02931923
6.09278575 6.15625227 6.21971879 6.28318531]

In [5]:
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

angles = linspace(0 * pi, 2 * pi, 100 )

xs = cos(angles)
ys = sin(angles)

plt.plot(xs, ys, color = 'green')

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


## Increase circle radius from 1 to 1.5

In [6]:
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.5
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


## Draw diameter of circle

In [7]:
#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.5
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(1.5, 0, marker = 'o', color = 'blue')
plt.plot(-1.5, 0, marker = 'o', color = 'blue')
plt.plot([1.5, -1.5], [0, 0])
plt.gca().annotate('Diameter', xy=(-0.5, -0.25), xycoords='data', fontsize=10)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


### Draw diameter from 90 degree

In [9]:
#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.5
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(0, 1.5, marker = 'o', color = 'blue')
plt.plot(0, -1.5, marker = 'o', color = 'blue')
plt.plot([0, 0], [1.5, -1.5])
plt.gca().annotate('Diameter', xy=(-0.25, -0.25), xycoords='data', fontsize=10, rotation = 90)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


In [10]:
#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
r = 1.5
angles = linspace(0 * pi, 2 * pi, 100 )
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(0, 1.5, marker = 'o', color = 'blue')
plt.plot(0, -1.5, marker = 'o', color = 'blue')
plt.plot([0, 0], [1.5, -1.5])
plt.gca().annotate('Diameter', xy=(-0.25, -0.25), xycoords='data', fontsize=10, rotation = 90)

plt.plot(0, 0, marker = 'o', color = 'purple')
plt.plot(1.5, 0, marker = 'o', color = 'purple')
plt.plot([0, 1.5], [0, 0], color = 'purple')

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


## Draw arc from 0 to pi/4

In [11]:
#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
r = 1.5
angles = linspace(0 * pi, 2 * pi, 100 )
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(0, 1.5, marker = 'o', color = 'blue')
plt.plot(0, -1.5, marker = 'o', color = 'blue')
plt.plot([0, 0], [1.5, -1.5])
plt.gca().annotate('Diameter', xy=(-0.25, -0.25), xycoords='data', fontsize=10, rotation = 90)

plt.plot(0, 0, marker = 'o', color = 'purple')
plt.plot(1.5, 0, marker = 'o', color = 'purple')
plt.plot([0, 1.5], [0, 0], color = 'purple')

#draw arc
arc_angles = linspace(0 * pi, pi/4, 20)
arc_xs = r * cos(arc_angles)
arc_ys = r * sin(arc_angles)
plt.plot(arc_xs, arc_ys, color = 'red', lw = 3)
plt.gca().annotate('Arc', xy=(1.5, 0.4), xycoords='data', fontsize=10, rotation = 120)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


### Draw radius from 0 to pi/4 and complete the arc

In [12]:
plt.figure(figsize = (18, 7))

#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 + 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
r = 1.5
angles = linspace(0 * pi, 2 * pi, 100 )
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(0, 1.5, marker = 'o', color = 'blue')
plt.plot(0, -1.5, marker = 'o', color = 'blue')
plt.plot([0, 0], [1.5, -1.5])
plt.gca().annotate('Diameter', xy=(-0.25, -0.25), xycoords='data', fontsize=10, rotation = 90)

#plt.plot(0, 0, marker = 'o', color = 'purple')
plt.plot(1.5, 0, marker = 'o', color = 'purple')
plt.plot([0, 1.5], [0, 0], color = 'purple')

#draw arc
arc_angles = linspace(0 * pi, pi/4, 20)
arc_xs = r * cos(arc_angles)
arc_ys = r * sin(arc_angles)
plt.plot(arc_xs, arc_ys, color = 'red', lw = 3)
plt.gca().annotate('Arc', xy=(1.5, 0.4), xycoords='data', fontsize=10, rotation = 120)

plt.plot(r * cos(pi /4), r * sin( pi / 4), marker = 'o', color = 'red')
plt.plot([0, r * cos(pi /4)], [0, r * sin( pi / 4)], color = "purple")

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


### Write annotation of arc

In [13]:
plt.figure(figsize = (18, 7))

#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 - 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
r = 1.5
angles = linspace(0 * pi, 2 * pi, 100 )
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(0, 1.5, marker = 'o', color = 'blue')
plt.plot(0, -1.5, marker = 'o', color = 'blue')
plt.plot([0, 0], [1.5, -1.5])
plt.gca().annotate('Diameter', xy=(-0.25, -0.25), xycoords='data', fontsize=10, rotation = 90)

#plt.plot(0, 0, marker = 'o', color = 'purple')
plt.plot(1.5, 0, marker = 'o', color = 'purple')
plt.plot([0, 1.5], [0, 0], color = 'purple')

#draw arc
arc_angles = linspace(0 * pi, pi/4, 20)
arc_xs = r * cos(arc_angles)
arc_ys = r * sin(arc_angles)
plt.plot(arc_xs, arc_ys, color = 'red', lw = 3)
#plt.gca().annotate('Arc', xy=(1.5, 0.4), xycoords='data', fontsize=10, rotation = 120)
plt.gca().annotate(r'Arc = r * $\theta$', xy=(1.3, 0.4), xycoords='data', fontsize=10, rotation = 120)

plt.plot(r * cos(pi /4), r * sin( pi / 4), marker = 'o', color = 'red')
plt.plot([0, r * cos(pi /4)], [0, r * sin( pi / 4)], color = "purple")

# draw theta angle
r1 = 0.5
arc_angles = linspace(0 * pi, pi/4, 20)
arc_xs = r1 * cos(arc_angles)
arc_ys = r1 * sin(arc_angles)
plt.plot(arc_xs, arc_ys, color = 'green', lw = 3)
plt.gca().annotate(r'$\theta$', xy=(0.5, 0.2), xycoords='data', fontsize=15, rotation = 90)
plt.gca().annotate('<----- r = 1.5 ---->', xy=(0 - 0.2, 0 + 0.2), xycoords='data', fontsize=15, rotation = 45)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()


## Draw segment(chord)

In [23]:
plt.figure(figsize = (18, 7))

#draw point at orgin
plt.plot(0,0, color = 'red', marker = 'o')
plt.gca().annotate('O (0, 0)', xy=(0 - 0.1, 0 + 0.1), xycoords='data', fontsize=10)

#draw circle
r = 1.5
angles = linspace(0 * pi, 2 * pi, 100 )
xs = r * cos(angles)
ys = r * sin(angles)

plt.plot(xs, ys, color = 'green')

#draw daimeter
plt.plot(0, 1.5, marker = 'o', color = 'blue')
plt.plot(0, -1.5, marker = 'o', color = 'blue')
plt.plot([0, 0], [1.5, -1.5])
plt.gca().annotate('Diameter', xy=(-0.25, -0.25), xycoords='data', fontsize=10, rotation = 90)

#plt.plot(0, 0, marker = 'o', color = 'purple')
plt.plot(1.5, 0, marker = 'o', color = 'purple')
plt.plot([0, 1.5], [0, 0], color = 'purple')

#draw arc
arc_angles = linspace(0 * pi, pi/4, 20)
arc_xs = r * cos(arc_angles)
arc_ys = r * sin(arc_angles)
plt.plot(arc_xs, arc_ys, color = 'red', lw = 3)
#plt.gca().annotate('Arc', xy=(1.5, 0.4), xycoords='data', fontsize=10, rotation = 120)
plt.gca().annotate(r'Arc = r * $\theta$', xy=(1.3, 0.4), xycoords='data', fontsize=10, rotation = 120)

plt.plot(r * cos(pi /4), r * sin( pi / 4), marker = 'o', color = 'red')
plt.plot([0, r * cos(pi /4)], [0, r * sin( pi / 4)], color = "purple")

# draw theta angle and annotation
r1 = 0.5
arc_angles = linspace(0 * pi, pi/4, 20)
arc_xs = r1 * cos(arc_angles)
arc_ys = r1 * sin(arc_angles)
plt.plot(arc_xs, arc_ys, color = 'green', lw = 3)
plt.gca().annotate(r'$\theta$', xy=(0.5, 0.2), xycoords='data', fontsize=15, rotation = 90)
plt.gca().annotate('<----- r = 1.5 ---->', xy=(0 - 0.2, 0 + 0.2), xycoords='data', fontsize=15, rotation = 45)

#draw segment
r2 = 1.5
segment_angles = linspace(3/4 * 2* pi, 2 * pi, 100 )
segment_xs = r2 * cos(segment_angles)
segment_ys = r2 * sin(segment_angles)

plt.plot(segment_xs, segment_ys, color = 'yellow')

plt.plot([1.5, 0], [0, -1.5], color = 'yellow')
plt.gca().annotate('Segment', xy=(0.5, -1.2), xycoords='data', fontsize=15, rotation = 45)
seg_x_p1 = r2 * cos(2 * pi)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()