我正试图用contour
命令绘制源流的速度等值线图。不知何故,我的轮廓一直集中在源点
有人能告诉我如何扩展轮廓来填充整个图形吗
这是我的密码
import math
import numpy
from matplotlib import pyplot
N = 50 # number of points in each direction
x_start, x_end = -1, 1 # boundaries in the x-direction
y_start, y_end = -1, 1 # boundaries in the y-direction
x = numpy.linspace(x_start, x_end, N) # creates a 1D-array with the x-coordinates
y = numpy.linspace(y_start, y_end, N) # creates a 1D-array with the y-coordinates
X, Y = numpy.meshgrid(x, y) # generates a mesh grid
strength_source = 5.0 # source strength
x_source, y_source = 0.0, 0.0 # location of the source
# compute the velocity field on the mesh grid
u_source = (strength_source / (2 * math.pi) *
(X - x_source) / ((X - x_source)**2 + (Y - y_source)**2))
v_source = (strength_source / (2 * math.pi) *
(Y - y_source) / ((X - x_source)**2 + (Y - y_source)**2))
Z = numpy.sqrt(u_source**2 + v_source**2)
cp = pyplot.contour(X, Y, Z)
pyplot.show()
您可以使用
contourf
,而不是contour
相关问题 更多 >
编程相关推荐