如何从 matplotlib seaborn 图中删除特定 child

How to delete specific child from matplotlib seaborn plot

我正在使用 seaborn jointplot 创建等高线图和各自的分布。

由于 pearsonr 与图中的信息无关,我想将其删除(以避免混淆)。在启动 seaborn jointplot 命令时,我既无法阻止它被放在那里,也没有找到从情节中删除 child 的方法。

ax.get_children()

命令returns以下child任:

[<matplotlib.axis.XAxis at 0x7f03778cdc90>,
 <matplotlib.axis.YAxis at 0x7f03778e5b90>,
 <matplotlib.legend.Legend at 0x7f0377703dd0>,
 <matplotlib.collections.PathCollection at 0x7f037ba60c90>,
 <matplotlib.collections.PathCollection at 0x7f0378325310>,
 <matplotlib.collections.PathCollection at 0x7f0377754a10>,
 <matplotlib.collections.PathCollection at 0x7f0377754f50>,
 <matplotlib.collections.PathCollection at 0x7f037776e4d0>,
 <matplotlib.collections.PathCollection at 0x7f037776ea10>,
 <matplotlib.collections.PathCollection at 0x7f037776ee90>,
 <matplotlib.collections.PathCollection at 0x7f03776f73d0>,
 <matplotlib.quiver.Quiver at 0x7f0377b79dd0>,
 <matplotlib.text.Text at 0x7f037789a6d0>,
 <matplotlib.text.Text at 0x7f037789a710>,
 <matplotlib.text.Text at 0x7f037789a750>,
 <matplotlib.patches.Rectangle at 0x7f037789a790>,
 <matplotlib.spines.Spine at 0x7f03778cdb50>,
 <matplotlib.spines.Spine at 0x7f0377953f50>,
 <matplotlib.spines.Spine at 0x7f03778cd9d0>,
 <matplotlib.spines.Spine at 0x7f03778bb390>]

但是 ax.get_children()[12].remove() 以

结束
raise NotImplementedError('cannot remove artist')

seaborn 似乎也以某种方式阻止了 plt.ion() or/and 其他重绘内容。 我希望解决方案非常简单(find_object 命令 + 删除的某种组合)。有什么建议吗?

来自docs

stat_func : callable or None

Function used to calculate a statistic about the relationship and annotate the plot. Should map x and y either to a single value or to a (value, p) tuple. Set to None if you don’t want to annotate the plot.

所以在调用jointplot时,只需将stat_func设置为None即可。