[Python] drawing a cool fish

Cool fish plot in Python

Cool fish plot in Python

Let’s bring a bit of art into our coding, shall we?
I randomly came across this plot and also a bunch of other ones (find them here), and
then decided to draw this cool fish in Python!

Here you will find the codes:

# Youtube.com/@codedabacus
# Fish plot

# libraries
import matplotlib.pyplot as plt
import numpy as np

# initialize storages for the x- and y coordinates of the endpoints
X, Y = [], []

# total lines
lines = 1000

# compute the endpoints
for i in range(1, lines+1):
  x1 = -2 * np.cos((4 * np.pi * i) / lines)
  y1 = 0.5 * np.cos((6 * np.pi * i) / lines) 

  x2 = (-2/15) * np.sin((6 * np.pi * i) / lines)
  y2 = (4/5) * np.sin((2 * np.pi * i) / lines)

  # update the containers
  X.extend([x1, x2, None])
  Y.extend([y1, y2, None])

# plot the line segments
fig = plt.figure(figsize = (10, 6))
plt.plot(X, Y, linewidth = 0.1, color = 'black')
fig.patch.set_facecolor('lightblue')
plt.axis('off')
plt.savefig('fish.png')
plt.show()

 

Also here you can find the step by step walkthrough for drawing this plot in Python:

 

 

 

Related Images: