3D Quiver

Electromagnetic Wave (E & B Fields)

Electromagnetic wave showing perpendicular oscillating electric (E) and magnetic (B) field vectors.

Output
Electromagnetic Wave (E & B Fields)
Python
import matplotlib.pyplot as plt
import numpy as np

# EM wave E and B fields
n = 8
z = np.linspace(0, 4*np.pi, n)
y_pos = np.array([0])
x_pos = np.array([0])

Z, Y, X = np.meshgrid(z, y_pos, x_pos)
Z = Z.flatten()
X = X.flatten()
Y = Y.flatten()

# E field (vertical oscillation)
U_E = np.zeros_like(Z)
V_E = np.sin(Z)
W_E = np.zeros_like(Z)

# B field (horizontal oscillation, perpendicular to E)
U_B = np.sin(Z)
V_B = np.zeros_like(Z)
W_B = np.zeros_like(Z)

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

# E field in cyan
ax.quiver(X, Y, Z, U_E, V_E, W_E, length=0.8, normalize=False,
          color='#06b6d4', alpha=0.9, arrow_length_ratio=0.2, label='E field')

# B field in magenta
ax.quiver(X, Y, Z, U_B, V_B, W_B, length=0.8, normalize=False,
          color='#ec4899', alpha=0.9, arrow_length_ratio=0.2, label='B field')

# Propagation direction
ax.plot([0, 0], [0, 0], [0, 4*np.pi], color='#fbbf24', linewidth=2, linestyle='--', alpha=0.5)

ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_zlim(0, 4*np.pi)

ax.set_xlabel('X', color='white', fontsize=10)
ax.set_ylabel('Y', color='white', fontsize=10)
ax.set_zlabel('Z (propagation)', color='white', fontsize=10)
ax.set_title('Electromagnetic Wave (E & B Fields)', color='white', fontsize=14, fontweight='bold', pad=20)
ax.legend(loc='upper right', fontsize=9, facecolor='#1e293b', edgecolor='#334155', labelcolor='white')

ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')

ax.view_init(elev=15, azim=30)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support