Step by Step Draw Boy Using Matplotlib Module

Step by Step Draw Boy Using Matplotlib Module

In this blog, we will draw boy using matplotlib module.

Import modules

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

Create a figure

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()

Draw face

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.

Move face up

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()

Draw mouth

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.

Move mouth 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()

Draw eyes

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()

Draw body

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()

Draw hands

Left hand

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()

Right hand

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()

Draw legs

left leg

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()

right leg

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()

Full code with background color and boy without points

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()

Boy's feeling loved with someone, let us draw.

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 [ ]:
 

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing