【问题标题】:How do I highlight a slice on a matplotlib 3D surface plot(using quiver)?如何突出显示 matplotlib 3D 曲面图上的切片(使用箭袋)?
【发布时间】:2022-12-10 16:34:27
【问题描述】:

我有以下 3D 图代码,想展示其中的一部分

import matplotlib.pyplot as plt
import numpy as np

ax = plt.figure().add_subplot(projection='3d')

# Make the grid
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))

# Make the direction data for the arrows
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
    np.sin(np.pi * z))

ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)

plt.show()

例如,当 z 为零时如何绘制这些箭头的一部分

如何重写这部分以便我获得绘图的二维切片?

ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)

plt.show()

例如,当 z 为零时如何绘制这些箭头的一部分

【问题讨论】:

    标签: matplotlib plot pythonplotter


    【解决方案1】:

    计算感兴趣切片上的矢量场,如下所示:

    n = 10j # number of discretization points
    # discretize a plane
    x, y = np.mgrid[-0.8:0.8:n, -0.8:0.8:n]
    z = 0 * np.ones_like(x)
    
    u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
    v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
    w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
        np.sin(np.pi * z))
    
    ax = plt.figure().add_subplot(projection='3d')
    ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)
    ax.set_zlim(-1, 1)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      相关资源
      最近更新 更多