# 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.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.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.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.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.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.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.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.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.axis("off")
plt.show()