为什么不能在表面上绘制箭袋?

问题描述 投票:0回答:1

我正在尝试使用 quiver 在表面上绘制 3 个箭头。箭头似乎总是画在表面后面。这是结果:

这是生成此结果的代码:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt


def fun(x, y):
    return x ** 2 - y ** 2


if __name__ == '__main__':
    fig = plt.figure(dpi=160)
    ax = fig.add_subplot(111, projection='3d')
    x = y = np.arange(-3.0, 3.0, 0.05)
    X, Y = np.meshgrid(x, y)
    zs = np.array(fun(np.ravel(X), np.ravel(Y)))
    Z = zs.reshape(X.shape)

    ax.plot_surface(X, Y, Z, cmap=plt.get_cmap('Blues'))

    ax.quiver([0], [0], [1], [0, -1, 0], [-1, 0, 0], [0, 0, 2.5], lw=4, color=['r', 'g', 'b'])  # The z is 1 unit above the surface

    ax.set_xlim3d(-3.5, 3.5)
    ax.set_ylim3d(-3.5, 3.5)
    ax.set_zlim3d(-8.5, 8.5)

    plt.show()

如何在表面上绘制这些箭头?我正在使用 matplotlib

3.1.1
,这是提出这个问题时的最新版本。

python python-3.x matplotlib surface matplotlib-3d
1个回答
0
投票

您可以使用的一个 hacky 解决方案虽然并不理想,但可以减少表面的 alpha。

ax.plot_surface(X, Y, Z, cmap=plt.get_cmap('Blues'), alpha=0.5)

© www.soinside.com 2019 - 2024. All rights reserved.