In this blog, we will draw boy using matplotlib module.
In [1]:
import matplotlib.pyplot as plt
from numpy import sin, cos, pi, linspace
Create figure and write figure size according to your choice. In this example i am using figure size(18,7) and setting x limit and y limit.
In [3]:
plt.figure(figsize = (18, 7))
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
We have to draw full circle for face. Angle will start from 0pi and it will go upto 2pi.
In [4]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys, color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
Face is showing in middle, we have to move up, so that we can get place for body and legs. Circle is drawing from origin(0, 0). To move up circle, we have to add value in y.
In [5]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
For mouth, we have to draw half circle. Angle will start from pi and it will go upto 2*pi.
In [6]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys, color = 'red')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
We can see mouth is not at correct place. Let us move up.
In [7]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [8]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [9]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [10]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
#left hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(-2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, -2], [0.75, -1.5], color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [53]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
#left hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(-2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, -2], [0.75, -1.5], color = 'black')
#right hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 2], [0.75, -1.5], color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [12]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
#left hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(-2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, -2], [0.75, -1.5], color = 'black')
#right hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 2], [0.75, -1.5], color = 'black')
#left leg
plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
plt.plot(-2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, -2], [-2.5, -4.5], color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [13]:
plt.figure(figsize = (18, 7))
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
#left hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(-2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, -2], [0.75, -1.5], color = 'black')
#right hand
plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
plt.plot(2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 2], [0.75, -1.5], color = 'black')
#left leg
plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
plt.plot(-2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, -2], [-2.5, -4.5], color = 'black')
#right leg
plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
plt.plot(2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, 2], [-2.5, -4.5], color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [2]:
plt.figure(figsize = (18, 7))
ax = plt.axes()
# Setting the background color of the plot
ax.set_facecolor("#05C3DD")
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
#plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
#plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
#left hand
#plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
#plt.plot(-2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, -2], [0.75, -1.5], color = 'black')
#right hand
#plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
#plt.plot(2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 2], [0.75, -1.5], color = 'black')
#left leg
#plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
#plt.plot(-2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, -2], [-2.5, -4.5], color = 'black')
#right leg
#plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
#plt.plot(2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, 2], [-2.5, -4.5], color = 'black')
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [54]:
plt.figure(figsize = (18, 7))
ax = plt.axes()
# Setting the background color of the plot
# using set_facecolor() method
#ax.set_facecolor("#05C3DD")
#face
angles = linspace(0 * pi, 2 * pi, 100 )
r = 1.2
xs = r * cos(angles)
ys = r * sin(angles)
plt.plot(xs, ys + 2, color = 'black')
#mouth
mouth_angles = linspace(pi, 2 * pi, 50 )
r1 = 0.5
mouth_xs = r1 * cos(mouth_angles)
mouth_ys = r1 * sin(mouth_angles)
plt.plot(mouth_xs, mouth_ys + 1.75, color = 'red')
#eyes
plt.plot(0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
plt.plot(-0.5, 2.4, color = 'grey', marker = 'o', markersize = 12)
#body
#plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
#plt.plot(0, -2.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 0], [0.75, -2.5], color = 'black')
#left hand
#plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
#plt.plot(-2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, -2], [0.75, -1.5], color = 'black')
#right hand
#plt.plot(0, 0.75, markersize = 8, color = 'red', marker = 'o')
#plt.plot(2, -1.5, markersize = 8, color = 'red', marker = 'o')
plt.plot([0, 2], [0.75, -1.5], color = 'black')
#left leg
#plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
#plt.plot(-2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, -2], [-2.5, -4.5], color = 'black')
#right leg
#plt.plot(0, -2.5, color = 'red', markersize = 8, marker = 'o')
#plt.plot(2, -4.5, color = 'red', markersize = 8, marker = 'o')
plt.plot([0, 2], [-2.5, -4.5], color = 'black')
#circle on head
circle_on_head_angles = linspace(0 * pi, 2 * pi, 100 )
r2 = 1
r3 = 0.25
head_circle_xs = r2 * cos(circle_on_head_angles)
head_circle_ys = r3 * sin(circle_on_head_angles)
plt.plot(head_circle_xs, head_circle_ys + 3.2, color = '#009FEC', linewidth = 5, alpha=0.3)
#heart
plt.plot(-1.2, 2, marker="$\u2665$", color='red', markersize = 30)
plt.plot(1.1, 1.5, marker="$\u2665$", color='red', markersize = 30)
plt.plot(1.1, 3.0, marker="$\u2665$", color='red', markersize = 30, alpha=0.3)
plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.gca().set_aspect('equal')
plt.show()
In [ ]:
In [ ]: