Saturday, 12 April 2025

DMT Grid Pattern using Python


import matplotlib.pyplot as plt

import numpy as np

from mpl_toolkits.mplot3d import Axes3D

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

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

x=np.linspace(-6*np.pi,6*np.pi,300)

y=np.linspace(-6*np.pi,6*np.pi,300)

x,y=np.meshgrid(x,y)

z=np.sin(x)*np.cos(y)+np.sin(y/2)*np.cos(x/2)

surf=ax.plot_surface(x,y,z,cmap='plasma',edgecolor='none',alpha=0.95)

ax.set_title('DMT Grid Pattern',fontsize=18,color='violet')

ax.set_xlabel('X Axis',color='white')

ax.set_ylabel('Y Axis',color='white')

ax.set_zlabel('Z Axis',color='white')

ax.grid(False)

ax.set_facecolor('black')

fig.patch.set_facecolor('black')

fig.colorbar(surf,shrink=0.5,aspect=5)

ax.xaxis.pane.fill=False

ax.yaxis.pane.fill=False

ax.zaxis.pane.fill=False

plt.tight_layout()

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

numpy: For efficient math operations and array handling.

matplotlib.pyplot: Used for plotting graphs and figures.

Axes3D: Enables 3D plotting capabilities in Matplotlib.

 2. Create a 3D Figure

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

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

fig = plt.figure(...): Creates a blank figure with size 10x7 inches.

 add_subplot(111, projection='3d'): Adds one subplot (1 row, 1 column, 1 plot) with 3D capabilities.

 3. Generate the X and Y Coordinate Grid

x = np.linspace(-6 * np.pi, 6 * np.pi, 300)

y = np.linspace(-6 * np.pi, 6 * np.pi, 300)

x, y = np.meshgrid(x, y)

np.linspace(...): Creates evenly spaced values from -6π to 6π.

meshgrid: Turns 1D arrays into 2D grid coordinates for surface plotting.

 4. Define the Z-Values (Height of the Surface)

z = np.sin(x) * np.cos(y) + np.sin(y/2) * np.cos(x/2)

This creates a complex wave interference pattern by combining sine and cosine waves.

It gives the surface a psychedelic, rippling effect—like a neural or energy grid.

 5. Plot the 3D Surface

surf = ax.plot_surface(x, y, z, cmap='plasma', edgecolor='none', alpha=0.95)

plot_surface: Draws the 3D surface based on x, y, and z.

cmap='plasma': Sets the color theme to a glowing, trippy gradient.

edgecolor='none': Removes mesh lines for a smooth appearance.

alpha=0.95: Sets surface transparency (slightly see-through).

 6. Set Titles and Axis Labels

ax.set_title('DMTGrid', fontsize=18, color='violet')

ax.set_xlabel('X Axis', color='white')

ax.set_ylabel('Y Axis', color='white')

ax.set_zlabel('Consciousness', color='white')

Gives the plot a title and axis labels.

Label text color is white for contrast against the dark background.

"Consciousness" instead of "Z Axis" adds a fun, mystical touch.

 7. Style the Plot for Psychedelic Effect

ax.grid(False)

ax.set_facecolor('black')

fig.patch.set_facecolor('black')

Turns off gridlines for a cleaner visual.

Sets the background color to black — enhances the plasma colors.

 8. Add a Color Bar (Legend for the Z Values)

fig.colorbar(surf, shrink=0.5, aspect=5)

Adds a side bar that shows the value range of the surface colors.

shrink and aspect adjust its size and shape.

 9. Hide Pane Backgrounds

ax.xaxis.pane.fill = False

ax.yaxis.pane.fill = False

ax.zaxis.pane.fill = False

Removes the gray panes behind the axes to keep the focus on the colorful surface.

 10. Final Layout & Show Plot

plt.tight_layout()

plt.show()

tight_layout(): Automatically adjusts spacing so labels and titles don't overlap.

 show(): Displays the final 3D plot.

 

Related Posts:

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (111) 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 (149) 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 (86) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1067) Python Coding Challenge (465) Python Quiz (138) 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)