Skip to content Skip to sidebar Skip to footer

Plotting A Streamplot Changing Coordinates

I want to plot a field given in polar coordinates. This can be done with quiver. However I want to get a streamplot # Field domain in polar coordinates: R2, THETA2 = np.mgrid[1:3:1

Solution 1:

streamplot expects the input to be a regular grid in cartesian coordinates. You have created a grid in polar coordinates. To fix this, you can initialize your grid in cartesian coordinates, then convert to polar, compute E_y and E_z using these polar coordinates and then plot it.

# Grid in cartesian coordinates
xrange = np.linspace(-10, 10);
yrange = np.linspace(-10, 10);

xx,yy = np.meshgrid(xrange, yrange)

# Convert each point in grid to polar coordinates
R2 = np.sqrt(xx**2 + yy **2)
THETA2 = np.arctan2(xx, yy)

# Compute direction vectors
E_y = np.cos(THETA2)*np.sin(THETA2)*(2+3/R2**3)
E_z = (1+2/R2**3)*np.cos(THETA2)**2 + (1+1/R2**3)*np.sin(THETA2)**2

# Plot:
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.quiver(xx, yy, E_y, E_z)
ax2.streamplot(xx, yy, E_y, E_z)

enter image description here

Post a Comment for "Plotting A Streamplot Changing Coordinates"