Atmospheric density and its changes due to altitude
The Earth's atmosphere is divided into layers that vary in temperature, density, pressure, and altitude. Today we will focus on one of these variables: air density; it is defined as the ratio between mass and volume :
The higher the altitude and the further from the surface, the lower the density. But why?
We can attribute this decrease to three factors:
- As altitude increases, there is less "air" above us, pressing down on us, decreasing the pressure and thus the density;
- Because gravity decreases as altitude increases, the effective weight of the air decreases, also decreasing the density;
- At higher altitudes, the air temperature becomes colder, thus becoming less dense.
Therefore, it is clear that understanding the atmospheric division is not simple, given the many factors involved. So, let's simplify our study and simulate a model in which the atmosphere is a single isothermal layer, that is, it has no temperature variation, and in which there is an exponential decrease in density with altitude:
For as density at sea level. Let's also assume a range for altitude, with 200 values between 0 and 80 km. From this, we can now establish these relationships on a graph and see how the density decays in this simplified model. Remember that in reality this process is much more complex and does not exclude temperature variation!

These are simulated data, not based on experimental measurements. This is merely a representation of the direct proportionality between the variables. A logarithmic scale was adopted for the y-axis and a linear scale for the x-axis for better visualization of the studied interval.

These are simulated data, not based on experimental measurements. This is simply a representation of the direct proportionality between the variables. The logarithmic scale was adopted for the y-axis and the x-axis for a better visualization of the function studied.
Therefore, we can see that, regardless of the scale, the decrease in density as altitude increases is observed and proven.
Code used for the simulations:
- Graphic 1:
import numpy as np
import matplotlib.pyplot as plt
import imageio
import os
def atmospheric_density(altitude):
"""
Calculate atmospheric density using an exponential model:
\rho(h) = \rho_0 * exp(-h/H)
Where:
- \rho_0 = 1.225 kg/m³ (density at sea level)
- H = 8.5 km (scale height)
"""
rho_0 = 1.225 # kg/m³ (density at sea level)
H = 8500 # metros (scale height)
return rho_0 * np.exp(-altitude / H)
# Generating altitude values from 0 to 80 km
altitudes = np.linspace(0, 80000, 200)
# Calculating atmospheric densities
densities = atmospheric_density(altitudes)
# Create a directory to store the frames
if not os.path.exists("frames"):
os.makedirs("frames")
# Generate frames for the GIF
for i in range(1, len(altitudes) + 1):
plt.figure(figsize=(8, 5))
plt.plot(altitudes[:i] / 1000, densities[:i], label='Densidade Atmosférica', color='b')
plt.xlabel('Altitude (km)')
plt.ylabel('Densidade (kg/m³)')
plt.title('Densidade Atmosférica vs. Altitude')
plt.yscale('log')
plt.legend()
plt.grid()
# Save the frame
filename = f"frames/frame_{i:03d}.png" # Pad with leading zeros for proper sorting
plt.savefig(filename)
plt.close()
# Create the GIF using imageio
frames = []
for i in range(1, len(altitudes) + 1):
filename = f"frames/frame_{i:03d}.png"
frames.append(imageio.imread(filename))
imageio.mimsave("atmospheric_density.gif", frames, fps=10)
print("GIF created successfully!")
- Graphic 2:
import numpy as np
import matplotlib.pyplot as plt
import imageio
import os
def atmospheric_density(altitude):
"""
Calculate atmospheric density using an exponential model:
\rho(h) = \rho_0 * exp(-h/H)
Where:
- \rho_0 = 1.225 kg/m³ (density at sea level)
- H = 8.5 km (scale height)
"""
rho_0 = 1.225 # kg/m³ (density at sea level)
H = 8500 # metros (scale height)
return rho_0 * np.exp(-altitude / H)
# Generating altitude values from 0 to 80 km
altitudes = np.linspace(0, 80000, 200)
# Calculating atmospheric densities
densities = atmospheric_density(altitudes)
# Create a directory to store the frames
if not os.path.exists("frames"):
os.makedirs("frames")
# Generate frames for the GIF
for i in range(1, len(altitudes) + 1):
plt.figure(figsize=(8, 5))
plt.plot(altitudes[:i] / 1000, densities[:i], label='Densidade Atmosférica', color='b')
plt.xlabel('Altitude (km)')
plt.ylabel('Densidade (kg/m³)')
plt.title('Densidade Atmosférica vs. Altitude')
# set scale to 'log' for both x and y axes
plt.xscale('log')
plt.yscale('log')
plt.legend()
plt.grid()
# Save the frame
filename = f"frames/frame_{i:03d}.png" # Pad with leading zeros for proper sorting
plt.savefig(filename)
plt.close()
# Create the GIF using imageio
frames = []
for i in range(1, len(altitudes) + 1):
filename = f"frames/frame_{i:03d}.png"
frames.append(imageio.imread(filename))
imageio.mimsave("atmospheric_density_exp.gif", frames, fps=10)
print("GIF created successfully!")