Sunday, 6 April 2025

Heat Wave Mirage Pattern using Python

 



import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

x = np.linspace(-5, 5, 100)

y = np.linspace(-5, 5, 100)

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

heat_source_x, heat_source_y = 0, 0 

sigma = 1.5  

Z = np.exp(-((X - heat_source_x)**2 + (Y - heat_source_y)**2) / (2 * sigma**2))

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

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

ax.plot_surface(X,Y,Z,cmap="hot",edgecolor="none")

ax.set_xlabel("X Axis")

ax.set_ylabel("Y Axis")

ax.set_zlabel("Heat Intensity")

ax.set_title("Heat Wave Mirage pattern")

ax.set_xticks([])

ax.set_yticks([])

ax.set_zticks([])

plt.show()

#source code --> clcoding.com 

Code Explanation:

Import Required Libraries

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

NumPy (np): Used for creating numerical arrays and mesh grids.

 Matplotlib (plt): Used for creating the 3D surface plot.

 mpl_toolkits.mplot3d: Enables 3D plotting in Matplotlib.

 

Create a Grid for Heat Simulation

x = np.linspace(-5, 5, 100)  # X-axis range (-5 to 5) with 100 points

y = np.linspace(-5, 5, 100)  # Y-axis range (-5 to 5) with 100 points

X, Y = np.meshgrid(x, y)     # Create a 2D mesh grid from x and y values

np.linspace(-5, 5, 100): Creates 100 evenly spaced points from -5 to 5 in both x and y directions.

 np.meshgrid(x, y): Creates a grid of (X, Y) points where each (x, y) pair forms a coordinate in a 2D plane.

 

Define Heat Source and Heat Diffusion Formula

heat_source_x, heat_source_y = 0, 0  # Heat source at (0,0)

sigma = 1.5  # Controls the spread of heat

Z = np.exp(-((X - heat_source_x)**2 + (Y - heat_source_y)**2) / (2 * sigma**2))

(heat_source_x, heat_source_y): Defines the center of the heat source.

sigma: Controls how fast heat dissipates (higher value = wider spread).

This equation models how heat intensity decreases as we move away from the heat source.

High intensity at (0,0) and gradual fading outward.

 

Create a 3D Plot

fig = plt.figure(figsize=(10, 7))  # Create figure with size 10x7

ax = fig.add_subplot(111, projection="3d")  # Add 3D subplot

fig = plt.figure(figsize=(10, 7)): Initializes a Matplotlib figure.

 ax = fig.add_subplot(111, projection="3d"): Creates a 3D plot area (ax).

 

Plot Heat Distribution as a 3D Surface

ax.plot_surface(X, Y, Z, cmap="hot", edgecolor="none")

plot_surface(X, Y, Z): Creates a 3D surface plot.

cmap="hot": Uses the "hot" color map, where:

Red & yellow = High heat

Black & dark orange = Low heat

edgecolor="none": Removes edges to make the plot smooth.

 

Customize Labels and Titles

ax.set_xlabel("X Axis")

ax.set_ylabel("Y Axis")

ax.set_zlabel("Heat Intensity")

ax.set_title("Heatwave Mirage - 3D Heat Diffusion Simulation")

Adds labels for X, Y, and Z axes.

Sets the plot title.

 Remove Grid Ticks for a Clean Look

ax.set_xticks([])

ax.set_yticks([])

ax.set_zticks([])

Hides grid ticks for a smoother visualization.

 

Display the Final Heatwave Mirage

plt.show()

Displays the 3D plot.


Related Posts:

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (98) AI (40) Android (24) AngularJS (1) Api (2) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (198) C (77) C# (12) C++ (83) Course (67) Coursera (251) Cybersecurity (25) Data Analysis (3) Data Analytics (3) 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 (36) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (85) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1055) Python Coding Challenge (461) Python Quiz (128) 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)