I have written a program where it takes a radius range(R to 5) and theta range(0 to 2pi). It converts the polar coordinates to Cartesian coordinates. Then I have plotted the scatter graph of the x,y Cartesian coordinates.
I have a free stream velocity u(x-direction)=1 and v-velocity(y-direction)= 0. I want to plot a stream plot for the points I have obtained above. I know I have to use meshgrid function. But after trying a lot, I cannot map the Mesh grid points to the velocity values.
I want to get a plot like below picture.
The Code is given below:
import math
import numpy as np
from matplotlib import pyplot
R=1.15; # Radius of circle
Nr=75; # No of radial points
Ntheta=75; # No of theta points
x_start,x_end=-5,5;
y_start,y_end=-5,5;
theta=np.linspace(0,2*np.pi,Ntheta); # Array of theta points
radial=np.linspace(R,5,Nr); # Array of radius points
xc=-0.15; # Center of circle.
yc=0.0; # Center of circle.
X,Y=np.meshgrid(r,theta); # Meshgrid for stream plot
x=np.zeros((Nr*Ntheta,1),dtype=np.float64); # To store x cordinates
y=np.zeros((Nr*Ntheta,1),dtype=np.float64); # to store y cordinates
# Z-Plane Computation
cnt=0;
for i in range(Nr):
for j in range(Ntheta):
x[cnt,0]=radial[i]*np.cos(theta[j])+xc; # Calculation of Cartesian Cordinates
y[cnt,0]=radial[i]*np.sin(theta[j])+yc; # Calculation of Cartesian Cordinates
cnt+=1;
# Plot
fig=pyplot.figure(figsize=(10,10));
pyplot.scatter(x[:,0],y[:,0],s=1,color='k');
pyplot.xlim(-6,6);
pyplot.ylim(-6,6);
pyplot.scatter(xc,yc,s=80,color='g',marker='o');
pyplot.title('Z-Plane',fontsize=20);
pyplot.xlabel('x',fontsize=15);
pyplot.ylabel('y',fontsize=15);
pyplot.grid(color='k',which='both',axis='both',linestyle='--',linewidth=0.5);
# StreamLine Velocity
u_inf=1;
u_freestream= u_inf*np.ones((Nr,Ntheta),dtype=np.float64);
v_freestream= np.zeros((Nr,Ntheta),dtype=np.float64);
#plotting
pyplot.figure()
pyplot.streamplot(X,Y,u_freestream,v_freestream);
The error is
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-59df08985fbe> in <module>()
46 #plotting
47 pyplot.figure()
---> 48 pyplot.streamplot(X,Y,u_freestream,v_freestream);
49
50
3 frames
/usr/local/lib/python3.6/dist-packages/matplotlib/streamplot.py in __init__(self, x, y)
342
343 if not np.allclose(np.diff(x), self.width / (self.nx - 1)):
--> 344 raise ValueError("'x' values must be equally spaced")
345 if not np.allclose(np.diff(y), self.height / (self.ny - 1)):
346 raise ValueError("'y' values must be equally spaced")
ValueError: 'x' values must be equally spaced




