3D Quiver
Gravitational Field - Binary System
Combined gravitational field vectors from two massive bodies in a binary system.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Gravitational field from two masses
n = 5
x = np.linspace(-3, 3, n)
y = np.linspace(-3, 3, n)
z = np.linspace(-2, 2, n)
X, Y, Z = np.meshgrid(x, y, z)
# Two masses at (-1.5, 0, 0) and (1.5, 0, 0)
m1_pos = np.array([-1.5, 0, 0])
m2_pos = np.array([1.5, 0, 0])
# Distance from each mass
r1 = np.sqrt((X - m1_pos[0])**2 + (Y - m1_pos[1])**2 + (Z - m1_pos[2])**2) + 0.5
r2 = np.sqrt((X - m2_pos[0])**2 + (Y - m2_pos[1])**2 + (Z - m2_pos[2])**2) + 0.5
# Combined gravitational field (pointing toward masses)
U = -(X - m1_pos[0])/r1**3 - (X - m2_pos[0])/r2**3
V = -(Y - m1_pos[1])/r1**3 - (Y - m2_pos[1])/r2**3
W = -(Z - m1_pos[2])/r1**3 - (Z - m2_pos[2])/r2**3
fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')
ax.quiver(X, Y, Z, U, V, W, length=0.4, normalize=True,
color='#a78bfa', alpha=0.8, arrow_length_ratio=0.3)
# Mark the masses
ax.scatter(*m1_pos, color='#fbbf24', s=200, marker='o')
ax.scatter(*m2_pos, color='#fbbf24', s=200, marker='o')
ax.set_xlim(-3.5, 3.5)
ax.set_ylim(-3.5, 3.5)
ax.set_zlim(-2.5, 2.5)
ax.set_xlabel('X', color='white', fontsize=10)
ax.set_ylabel('Y', color='white', fontsize=10)
ax.set_zlabel('Z', color='white', fontsize=10)
ax.set_title('Gravitational Field - Binary System', color='white', fontsize=14, fontweight='bold', pad=20)
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=20, azim=45)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
☕