import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
theta = np.linspace(0, 15 * np.pi, 1000)
z = np.linspace(-3, 3, 1000)
r = np.abs(np.sin(5 * z)) + 0.5
x = r * np.cos(theta)
y = r * np.sin(theta)
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z, color='magenta', linewidth=2)
ax.scatter(x, y, z, c=np.abs(z), cmap='plasma', s=2)
ax.set_title('Plasma Whirl 3D Pattern', fontsize=18, color='yellow')
ax.set_facecolor('black')
fig.patch.set_facecolor('black')
ax.grid(False)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
plt.show()
#source code --> clcoding.com
Code Explanation:
1. Importing Required Libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
numpy → For mathematical operations and creating
data points.
a) Angle Values for Rotation
theta = np.linspace(0, 15 * np.pi, 1000)
Creates values from 0 to 15π (about 7.5 full
rotations).
z = np.linspace(-3, 3, 1000)
Creates points from -3 to 3.
r = np.abs(np.sin(5 * z)) + 0.5
Radius is dynamic, based on a sine wave of z.
x = r * np.cos(theta)
y = r * np.sin(theta)
Converts polar coordinates (r, θ) to Cartesian (x,
y) for 3D plotting.
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection='3d')
Sets the plot size.
ax.plot(x, y, z, color='magenta', linewidth=2)
Draws the spiral line.
ax.scatter(x, y, z, c=np.abs(z), cmap='plasma', s=2)
Adds glowing dots along the spiral.
ax.set_title('Plasma Whirl 3D Pattern', fontsize=18,
color='yellow')
ax.set_facecolor('black')
fig.patch.set_facecolor('black')
ax.grid(False)
Title in yellow color.
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
Hides x, y, z axis ticks for a pure design look.
plt.show()
Shows the final plot.
0 Comments:
Post a Comment