【问题标题】:How do I specify the order of plots in Matplotlib?如何在 Matplotlib 中指定绘图的顺序?
【发布时间】:2019-02-20 07:17:51
【问题描述】:

我试图环顾四周来解决我的问题,一些答案指出 Matplotlib 的 zorder 有错误,而其他人则说它适用于他们。无论如何,这是导致问题的图像和代码:

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


fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(0, 7)
ax.set_ylim(0, 7)
ax.set_zlim(0, 7)
ax.view_init(elev=20, azim=32)

# u
ax.quiver(0, 0, 0, 1, 1, 0, color='C0', arrow_length_ratio=0.1, 
label=r'$\vec{u}$', zorder=10)

# v
ax.quiver(0, 0, 0, 2, 2, 0, color='C1', arrow_length_ratio=0.1, 
label=r'$\vec{v}$', zorder=0)

plt.legend()
ax.set_xlabel(r'$x$', fontsize='large')
ax.set_ylabel(r'$y$', fontsize='large')
ax.set_zlabel(r'$z$', fontsize='large')

plt.show()

此代码生成以下图像:

我希望蓝色箭头位于橙色箭头之上。指定 zorder 似乎不起作用。有人好心给我一些提示和建议吗?

谢谢。

【问题讨论】:

  • zorder 在 3D 图中被忽略(这在您明确定义 z 时是有意义的),请参阅 here。我的第一个想法是简单地将蓝色误差提高少量(例如 0.01),但结果并不令人信服。

标签: python matplotlib


【解决方案1】:

使 U 向量脱颖而出的可能解决方案是改变它的粗细,使其比向量 V 稍大。这样做的方法是使用linewidths 参数,请参阅Change size of arrows using matplotlib quiver。在你的情况下是这样的:

# u
ax.quiver(0, 0, 0, 1, 1, 0, color='C0', arrow_length_ratio=0.1, linewidths=2.5,
label=r'$\vec{u}$', zorder=10) 

# v
ax.quiver(0, 0, 0, 2, 2, 0, color='C1', arrow_length_ratio=0.1, linewidths=1., 
label=r'$\vec{v}$', zorder=0)

虽然,我意识到这可能不是您想要做的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 2014-01-08
    相关资源
    最近更新 更多