集中在中心的速度等值线

2024-05-14 03:05:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图用contour命令绘制源流的速度等值线图。不知何故,我的轮廓一直集中在源点

contour_map

有人能告诉我如何扩展轮廓来填充整个图形吗

这是我的密码

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()

Tags: oftheinimportnumpysourcemathstart