How Do I Use Quiver In Python For Polar?
Firstly, yes I have read previous threads and documentation about this issue, for example How to make a quiver plot in polar coordinates. This didn't help me all the way. Let me sh
Solution 1:
The only real problem with your code was a numpy
problem, i.e. in your dr
has the wrong dimensions. With slight adjustments to your code:
from matplotlib import pyplot as plt
import numpy as np
#to make the code runnable
u_sol = [1]
alpha0 = 5*np.pi/180
alpha = 10*np.pi/180
radii = np.linspace(0.2,1,10)
print(radii)
thetas = np.linspace(alpha0-alpha,alpha0+alpha,20)
print(thetas)
theta, r = np.meshgrid(thetas, radii)
q = 0.0001
#dr = [-q/x for x in radii]*u_sol[0]
dr = -q/r
dt = 0
f = plt.figure()
ax = f.add_subplot(111, polar=True)
ax.quiver(
theta, r,
dr * np.cos(theta) - dt * np.sin(theta),
dr * np.sin(theta) + dt * np.cos(theta),
)
plt.show()
I get the following image:
Note that in the radii
definition, I moved the lower limit from 0.1 to 0.2 as otherwise the arrows get so long that they point to the other side of the origin, which looks quite weird.
Post a Comment for "How Do I Use Quiver In Python For Polar?"