Thursday, 10 April 2025

Quantum Vortex 3D Pattern using Python

 


import matplotlib.pyplot as plt

import numpy as np

from mpl_toolkits.mplot3d import Axes3D

theta=np.linspace(0,20*np.pi,1000)

z=np.linspace(-2,2,1000)

r=z**2+1

x=r*np.sin(theta)

y=r*np.cos(theta)

fig=plt.figure(figsize=(6,8))

ax=fig.add_subplot(111,projection='3d')

ax.plot(x,y,z,color='cyan',linewidth=2)

ax.set_title('Quantum Vortex Pattern',fontsize=18,color='purple')

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. Import Required Libraries

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

Purpose:

numpy → For mathematical calculations like arrays, linspace, trigonometric functions.

 matplotlib.pyplot → For plotting the graph.

 mpl_toolkits.mplot3d → To enable 3D plotting using Matplotlib.

 2. Define the Vortex Parameters

theta = np.linspace(0, 20 * np.pi, 1000) 

z = np.linspace(-2, 2, 1000)            

r = z**2 + 1

Explanation:

theta → Controls the angle of the spiral (0 to 20π means multiple spiral loops).

 z → Controls the vertical height of the plot (-2 to 2 units).

 r → Radius of the spiral at each z height.

(As z increases or decreases, radius changes — gives a vortex or tornado effect).

 3. Generate X, Y, Z Coordinates

x = r * np.sin(theta)

y = r * np.cos(theta)

Purpose:

Parametric equations of a spiral in 3D:

 x depends on sin(theta)

 y depends on cos(theta)

 z is already defined.

 This gives the 3D twisted spiral shape.

 4. Create 3D Plot Figure

fig = plt.figure(figsize=(10, 7))

ax = fig.add_subplot(111, projection='3d')

Explanation:

Create a new figure of size 10x7.

 Add a 3D subplot to draw 3D patterns.

 5. Plot the Quantum Vortex

ax.plot(x, y, z, color='cyan', linewidth=2)

Purpose:

Draw the 3D vortex spiral using the x, y, z points.

 Color: Cyan

 Line width: 2

 6. Styling the Plot

ax.set_title('Quantum Vortex 3D Pattern', fontsize=18, color='purple')

ax.set_facecolor('black')

fig.patch.set_facecolor('black')

ax.grid(False)

Purpose:

Add a custom title to the plot.

 Set background color of the plot & figure to black for a "space" or "quantum" look.

 Disable grid lines for a clean visual.

 7. Remove Axis Ticks

ax.set_xticks([])

ax.set_yticks([])

ax.set_zticks([])

Purpose:

Remove the axis ticks (numbers) for an aesthetic and clean design.

 8. Show the Final Plot

plt.show()

Purpose:

Display the final 3D vortex pattern on the screen.


Related Posts:

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (114) AI (41) Android (24) AngularJS (1) Api (2) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (200) C (77) C# (12) C++ (83) Course (67) Coursera (253) Cybersecurity (25) Data Analysis (3) Data Analytics (4) data management (11) Data Science (150) Data Strucures (8) Deep Learning (21) Django (16) Downloads (3) edx (2) Engineering (14) Euron (29) Events (6) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Generative AI (11) Google (38) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (87) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1068) Python Coding Challenge (465) Python Quiz (140) Python Tips (5) Questions (2) R (70) React (6) Scripting (3) security (3) Selenium Webdriver (4) Software (17) SQL (42) UX Research (1) web application (8) Web development (4) web scraping (2)

Followers

Python Coding for Kids ( Free Demo for Everyone)