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.
0 Comments:
Post a Comment