Draw Some Interesting Pattern With Numpy & Matplotlib Module

Draw Some Interesting Pattern With Numpy & Matplotlib Module

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

Plot a point

In [2]:
plt.figure(figsize=(6, 6))

plt.plot(0, 0, marker = "o", color = "red")

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

Plot pattern 1

In [6]:
plt.figure(figsize=(6, 6))

plt.plot(0, 0, marker = "o", color = "red")

for idx in range(6):
    theta = 2 * pi * idx/6
    plt.plot(0.5 * cos(theta), 0.5 * sin(theta), marker = 'o', markersize = 8)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
In [7]:
plt.figure(figsize=(6, 6))

plt.plot(0, 0, marker = "o", color = "red")

for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(0.5 * cos(theta), 0.5 * sin(theta), marker = 'o', markersize = 8)

for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(0.75 * cos(theta), 0.75 * sin(theta), marker = 'o', markersize = 10)

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
In [8]:
plt.figure(figsize=(6, 6))

plt.plot(0, 0, marker = "o", color = "red")

for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(0.5 * cos(theta), 0.5 * sin(theta), marker = 'o', markersize = 8)

for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(0.75 * cos(theta), 0.75 * sin(theta), marker = 'o', markersize = 10)

for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(1 * cos(theta), 1 * sin(theta), marker = 'o', markersize = 12)
    
for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(1.25 * cos(theta), 1.25 * sin(theta), marker = 'o', markersize = 14)
    
for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(1.5 * cos(theta), 1.5 * sin(theta), marker = 'o', markersize = 16)
    
for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(1.75 * cos(theta), 1.75 * sin(theta), marker = 'o', markersize = 18)
    

plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal', adjustable='box')
plt.axis("off")
plt.show()

Plot another pattern

In [9]:
plt.figure(figsize=(6, 6))

plt.plot(0, 0, marker = "o", color = "black")

for idx in range(4):
    theta = 2 * pi * idx/4
    plt.plot(0.25 * cos(theta), 0.25 * sin(theta), marker = 'o', markersize = 10, color = "red")


plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.gca().set_aspect('equal', adjustable='box')
plt.show()
In [10]:
plt.figure(figsize=(6, 6))

plt.plot(0, 0, marker = "o", color = "black")

for idx in range(4):
    theta = 2 * pi * idx/4
    plt.plot(0.25 * cos(theta), 0.25 * sin(theta), marker = 'o', markersize = 10)

for idx in range(8):
    theta = 2 * pi * idx/8
    plt.plot(0.5 * cos(theta), 0.5 * sin(theta), marker = 'o', markersize = 10)

for idx in range(12):
    theta = 2 * pi * idx/12
    plt.plot(0.75 * cos(theta), 0.75 * sin(theta), marker = 'o', markersize = 10)
    
for idx in range(16):
    theta = 2 * pi * idx/16
    plt.plot(1 * cos(theta), 1 * sin(theta), marker = 'o', markersize = 10)
    
for idx in range(20):
    theta = 2 * pi * idx/20
    plt.plot(1.25 * cos(theta), 1.25 * sin(theta), marker = 'o', markersize = 10)

for idx in range(24):
    theta = 2 * pi * idx/24
    plt.plot(1.5 * cos(theta), 1.5 * sin(theta), marker = 'o', markersize = 10)
    
for idx in range(30):
    theta = 2 * pi * idx/30
    plt.plot(2 * cos(theta), 2 * sin(theta), marker = 'o', markersize = 10)
    
plt.xlim(-2.5, 2.5)
plt.ylim(-2.5, 2.5)
plt.gca().set_aspect('equal', adjustable='box')
plt.axis("off")
plt.show()

Draw rainbow

In [11]:
plt.figure(figsize=(6, 6))

for idx in range(9):
    r = 0.5
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "violet")
    pass

for idx in range(9):
    r = 0.75
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "indigo")
    pass

for idx in range(9):
    r = 1
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "blue")
    pass

for idx in range(9):
    r = 1.25
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "green")
    pass

for idx in range(9):
    r = 1.5
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "yellow")
    pass

for idx in range(9):
    r = 1.75
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "orange")
    pass

for idx in range(9):
    r = 2
    theta = pi * idx / 8
    plt.plot(r * cos(theta), r * sin(theta), marker = 'o', markersize = 10, color = "red")
    pass


plt.xlim(-2.5, 2.5)
plt.ylim(-2.5, 2.5)
plt.gca().set_aspect('equal', adjustable='box')
plt.axis("off")
plt.show()
In [10]:
plt.figure(figsize=(6, 6))

angles = linspace(0 * pi, pi, 100)
r1 = 1
xs = r1 * cos(angles)
ys = r1 * sin(angles)

plt.plot(xs, ys, color = "violet", lw = 20)

r2 = 1.2
xs = r2 * cos(angles)
ys = r2 * sin(angles)
plt.plot(xs, ys, color = "indigo", lw = 20)

r3 = 1.4
xs = r3 * cos(angles)
ys = r3 * sin(angles)
plt.plot(xs, ys, color = "blue", lw = 20)

r4 = 1.6
xs = r4 * cos(angles)
ys = r4 * sin(angles)
plt.plot(xs, ys, color = "green", lw = 20)

r5 = 1.8
xs = r5 * cos(angles)
ys = r5 * sin(angles)
plt.plot(xs, ys, color = "yellow", lw = 20)

r6 = 2
xs = r6 * cos(angles)
ys = r6 * sin(angles)
plt.plot(xs, ys, color = "orange", lw = 20)


r7 = 2.2
xs = r7 * cos(angles)
ys = r7 * sin(angles)
plt.plot(xs, ys, color = "red", lw = 20)




plt.xlim(-2.5, 2.5)
plt.ylim(-2.5, 2.5)
plt.gca().set_aspect('equal', adjustable='box')
plt.title("Rainbow")
plt.axis("off")

plt.show()

Draw some more pattern

In [46]:
plt.figure(figsize=(6, 6))


plt.plot(0, 0, marker = '*', color = 'grey', markersize = 8)

#plot stars 
for idx in range(8):
    theta = 2 * pi * idx / 8
    plt.plot(cos(theta), sin(theta), marker = '*', markersize = 10)
    pass

#plot first circle
angles = linspace(0 * pi, 2 * pi, 100)
r1 = 2

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

plt.plot(xs, ys, color = "grey")

#plot stars on first circle
for idx in range(8):
    theta = 2 * pi * idx / 8
    plt.plot(r1 * cos(theta), r1 * sin(theta), marker = '*', markersize = 10)
    pass

#plot second circle
angles = linspace(0 * pi, 2 * pi, 100)
r2 = 3

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

plt.plot(xs, ys, color = "grey")

#plot stars on second circle
for idx in range(8):
    theta = 2 * pi * idx / 8
    plt.plot(r2 * cos(theta), r2 * sin(theta), marker = '*', markersize = 10)
    pass


#plot third circle
angles = linspace(0 * pi, 2 * pi, 100)
r3 = 4

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

plt.plot(xs, ys, color = "grey")

#plot stars on third circle
for idx in range(8):
    theta = 2 * pi * idx / 8
    plt.plot(r3 * cos(theta), r3 * sin(theta), marker = '*', markersize = 10)
    pass

#plot forth circle
angles = linspace(0 * pi, 2 * pi, 100)
r4 = 4

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

plt.plot(xs, ys, color = "grey")

#plot stars on forth circle
for idx in range(16):
    theta = 2 * pi * idx / 16
    plt.plot(r4 * cos(theta), r4 * sin(theta), marker = '*', markersize = 10)
    pass


#plot stars without circle
for idx in range(16):
    theta = 2 * pi * idx / 16
    plt.plot(r5 * cos(theta), r5 * sin(theta), marker = '*', markersize = 10)
    pass



plt.xlim(-6, 6)
plt.ylim(-6, 6)
plt.gca().set_aspect('equal', adjustable='box')
plt.axis("off")
plt.show()

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