Processing math: 100%

使用 Python 计算向量场的旋度并在 Matplotlib 中绘图


为了使用 Python 计算向量场的旋度并在 Matplotlib 中绘图,我们可以使用 **quiver()** 方法并计算相应的数据。

步骤

  • 设置图形大小并调整子图之间和周围的填充。
  • 使用 **figure()** 方法创建一个新图形或激活现有图形。
  • 将 3D 坐标轴添加到图形中,作为子图排列的一部分。
  • 使用 numpy meshgrid 创建 **x**、**y** 和 **z** 数据点。
  • 创建 **u**、**v** 和 **w** 数据旋度向量位置。
  • 使用 **quiver()** 方法获取向量。
  • 关闭坐标轴。
  • 要显示图形,请使用 **show()** 方法。

示例

import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig = plt.figure()

ax = fig.add_subplot(projection='3d')

x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
                     np.arange(-0.8, 1, 0.2),
                     np.arange(-0.8, 1, 0.8))

u = 0
v = y**2
w = -2*y*z - y

ax.quiver(x, y, z, u, v, w, length=0.1)
ax.axis('off')

plt.show()

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

输出

更新于:2021年6月15日

1K+ 次浏览

启动你的 职业生涯

通过完成课程获得认证

开始学习
广告