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.
Information about circles
Circle
A circle is a shape consisting of all points in a plane that are at a given distance from a given point, the center; 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 center is called the radius.
Circumference
The distance around the circle.
Center
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 center; or the length of such a line segment. This is the largest distance between any two points on the circle.
Radius
The distance between any point of the circle and the center 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
import matplotlib.pyplot as plt
import numpy as np
from numpy import sin, cos, pi, linspace
Plot point at origin(0, 0)
#draw point at origin (0, 0)
plt.plot(0,0, color = 'red', marker = 'o')
plt.show()
Output:
Add annotation and set xlim and ylim
#draw point at origin (0, 0)
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)plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()
Output:
Draw a circle
#draw point at origin (0, 0)
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 a circle
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()
Output:
Increase circle radius from 1 to 1.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)#draw a 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')plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()
Output:
Draw diameter of circle
#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 a 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()
Output:
Draw diameter from 90 degree
#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()
Output:
Draw radius
#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)#draw radius
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.gca().annotate('Radius', xy=(0.5, -0.2), xycoords='data', fontsize=10)plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()
Output:
Draw arc from 0 to pi/4
#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)#draw radius
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.gca().annotate('Radius', xy=(0.5, -0.2), xycoords='data', fontsize=10)#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()
Output:
Draw radius from 0 to pi/4 and complete the arc
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)#draw radius
#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.gca().annotate('Radius', xy=(0.5, -0.2), xycoords='data', fontsize=10)#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)#draw another radius
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()
Output:
Write annotation of arc
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)#draw radius
#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.gca().annotate('Radius', xy=(0.5, -0.2), xycoords='data', fontsize=10)#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)#draw another radius
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)plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal')
plt.show()
Output:
Draw segment(chord)
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)#draw radius
#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.gca().annotate('Radius', xy=(0.5, -0.2), xycoords='data', fontsize=10)#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)#draw another radius
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()
Output:
That’s it. Thanks for reading.