在 seaborn facetGrid 上绘制艺术家

draw artists over seaborn facetGrid

我想在 facetGrid 的所有面板上绘制箭头。

在这个虚拟示例中,我想在所有面板上绘制相同的箭头:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pylab as plt


datDf=pd.DataFrame({'values':np.random.randint(0,100,100)})
datDf['group']=np.random.randint(0,5,100)
g = sns.FacetGrid(datDf, col="group",
                  col_wrap=3,
                  size=4.5,
                  sharex=True, sharey=True, despine=False)
g.map(plt.plot,'values')

for ax in g.axes:
    arrow=plt.arrow(0,0,50,50,width=5,
            length_includes_head=True,
            head_width=5*2,
            color='gray')
    ax.add_artist(arrow)

我收到这个错误:

ValueError:无法重置轴。您可能正在尝试在多个不受支持的 Axes 中重复使用一位艺术家

在 facetGrids 上绘制艺术家的正确方法是什么?

您可以使用 ax.arrow 而不是 plt.arrow 在坐标轴上绘制箭头。

这应该有效:

for ax in g.axes:
    ax.arrow(0,0,50,50,width=5,
            length_includes_head=True,
            head_width=5*2,
            color='gray')