3D Fill Between

3D Magnetic Flux Tube

Astrophysics visualization of magnetic flux tube structure with plasma flow.

Output
3D Magnetic Flux Tube
Python
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(12, 9), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d')
ax.set_facecolor('#0a0a0f')

n = 350
t = np.linspace(0, 10*np.pi, n)
z = np.linspace(0, 6, n)

# Twisted flux tube
twist = 0.3 * np.sin(z * np.pi / 2)
r_outer = 1 + 0.2 * np.sin(z * 2)
r_inner = 0.5 + 0.1 * np.sin(z * 2)

x_outer = r_outer * np.cos(t + twist)
y_outer = r_outer * np.sin(t + twist)

x_inner = r_inner * np.cos(t + twist)
y_inner = r_inner * np.sin(t + twist)

ax.plot(x_outer, y_outer, z, linewidth=2.5, color='#F5276C')
ax.plot(x_inner, y_inner, z, linewidth=2, color='#F5B027')

# Magnetic field lines
for i in range(0, n, 4):
    ax.plot([x_outer[i], x_inner[i]], [y_outer[i], y_inner[i]], [z[i], z[i]], 
            color='#27D3F5', alpha=0.3, linewidth=0.6)

ax.set_xlabel('X', fontsize=11, color='white')
ax.set_ylabel('Y', fontsize=11, color='white')
ax.set_zlabel('Height', fontsize=11, color='white')
ax.set_title('Magnetic Flux Tube', fontsize=14, color='white', fontweight='bold', pad=15)

ax.tick_params(colors='#888888', labelsize=9)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#333333')
ax.yaxis.pane.set_edgecolor('#333333')
ax.zaxis.pane.set_edgecolor('#333333')
ax.grid(True, alpha=0.3, color='#555555')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support