3D Quiver

Fluid Flow: Source and Sink

Fluid dynamics showing flow from a source point to a sink point in 3D space.

Output
Fluid Flow: Source and Sink
Python
import matplotlib.pyplot as plt
import numpy as np

# Fluid flow with source and sink
n = 6
x = np.linspace(-3, 3, n)
y = np.linspace(-3, 3, n)
z = np.linspace(-1, 1, 3)
X, Y, Z = np.meshgrid(x, y, z)

# Source at (-1.5, 0) and sink at (1.5, 0)
src = np.array([-1.5, 0])
snk = np.array([1.5, 0])

r_src = np.sqrt((X - src[0])**2 + (Y - src[1])**2) + 0.3
r_snk = np.sqrt((X - snk[0])**2 + (Y - snk[1])**2) + 0.3

# Outward from source, inward to sink
U = (X - src[0])/r_src**2 - (X - snk[0])/r_snk**2
V = (Y - src[1])/r_src**2 - (Y - snk[1])/r_snk**2
W = np.zeros_like(X)

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

ax.quiver(X, Y, Z, U, V, W, length=0.35, normalize=True,
          color='#059669', alpha=0.8, arrow_length_ratio=0.3)

# Mark source and sink
ax.scatter([src[0]], [src[1]], [0], color='#22c55e', s=150, marker='^', label='Source')
ax.scatter([snk[0]], [snk[1]], [0], color='#ef4444', s=150, marker='v', label='Sink')

ax.set_xlim(-3.5, 3.5)
ax.set_ylim(-3.5, 3.5)
ax.set_zlim(-1.5, 1.5)

ax.set_xlabel('X', color='#1f2937', fontsize=10)
ax.set_ylabel('Y', color='#1f2937', fontsize=10)
ax.set_zlabel('Z', color='#1f2937', fontsize=10)
ax.set_title('Fluid Flow: Source and Sink', color='#1f2937', fontsize=14, fontweight='bold', pad=20)
ax.legend(loc='upper right', fontsize=9)

ax.tick_params(colors='#6b7280', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#e5e7eb')
ax.yaxis.pane.set_edgecolor('#e5e7eb')
ax.zaxis.pane.set_edgecolor('#e5e7eb')

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

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support