Contour Plot

Electric Dipole Field

Electric potential field showing equipotential lines around positive and negative charges.

Output
Electric Dipole Field
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Create grid
x = np.linspace(-5, 5, 300)
y = np.linspace(-5, 5, 300)
X, Y = np.meshgrid(x, y)

# Point charges dipole
charges = [(1.5, 0, 1), (-1.5, 0, -1)]

# Calculate potential
V = np.zeros_like(X)
for cx, cy, q in charges:
    r = np.sqrt((X - cx)**2 + (Y - cy)**2)
    r = np.maximum(r, 0.3)
    V += q / r
V = np.clip(V, -5, 5)

# Physics neon theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#05050f')
ax.set_facecolor('#05050f')

# Custom colormap - electric blue to red
colors = ['#0044ff', '#2266ff', '#4488ff', '#66aaff', '#88ccff', 
          '#ffffff', '#ffcc88', '#ffaa66', '#ff8844', '#ff4400']
cmap = LinearSegmentedColormap.from_list('electric', colors, N=256)

# Filled contour
levels = np.linspace(-5, 5, 35)
cf = ax.contourf(X, Y, V, levels=levels, cmap=cmap, extend='both')

# Equipotential lines
cs = ax.contour(X, Y, V, levels=np.linspace(-4, 4, 16), colors='white', 
                linewidths=0.4, alpha=0.4)

# Mark charges with glow effect
ax.scatter([1.5], [0], color='#ff4400', s=250, marker='o', zorder=6, 
           edgecolors='white', linewidths=2)
ax.scatter([1.5], [0], color='#ff4400', s=500, marker='o', zorder=5, alpha=0.2)
ax.text(1.5, -0.8, '+', fontsize=20, color='white', ha='center', fontweight='bold')

ax.scatter([-1.5], [0], color='#0066ff', s=250, marker='o', zorder=6, 
           edgecolors='white', linewidths=2)
ax.scatter([-1.5], [0], color='#0066ff', s=500, marker='o', zorder=5, alpha=0.2)
ax.text(-1.5, -0.8, '-', fontsize=24, color='white', ha='center', fontweight='bold')

# Styled colorbar
cbar = plt.colorbar(cf, ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#05050f')
cbar.set_label('Electric Potential (V)', fontsize=11, color='#d0d0f0', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#d0d0f0')
cbar.outline.set_edgecolor('#2a2a4a')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#d0d0f0', fontsize=9)

# Labels
ax.set_xlabel('x (m)', fontsize=13, color='#d0d0f0', fontweight='600', labelpad=10)
ax.set_ylabel('y (m)', fontsize=13, color='#d0d0f0', fontweight='600', labelpad=10)
ax.set_title('Electric Dipole Potential Field', fontsize=16, color='white', 
             fontweight='bold', pad=20)

# Style axes
ax.tick_params(colors='#a0a0c0', labelsize=10, length=0)
for spine in ax.spines.values():
    spine.set_visible(False)

ax.set_aspect('equal')
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support