seaborn找不到包含

2024-04-25 21:40:12 发布

您现在位置:Python中文网/ 问答频道 /正文

seaborn tutorial我画了一个图:

import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.swarmplot(x=tips["total_bill"])

现在我想获得包含到make in interactive using mpld3的数据的PathCollection的句柄。我查看输出ax子级,得到以下列表:

[<matplotlib.collections.PathCollection at 0x7828d325f8>,
 <matplotlib.spines.Spine at 0x782824a518>,
 <matplotlib.spines.Spine at 0x782824ab38>,
 <matplotlib.spines.Spine at 0x782824a748>,
 <matplotlib.spines.Spine at 0x782824a940>,
 <matplotlib.axis.XAxis at 0x782824acf8>,
 <matplotlib.axis.YAxis at 0x78282e5518>,
 <matplotlib.text.Text at 0x78282fb710>,
 <matplotlib.text.Text at 0x78282fb0b8>,
 <matplotlib.text.Text at 0x78282fb208>,
 <matplotlib.patches.Rectangle at 0x78282fb0f0>]

但是,当我在PathCollection中查找数据时,它是空的 ax.get_children()[0].get_array()

如何找到包含数据点的PathCollection的句柄?你知道吗


Tags: 数据textgetmatplotlibseabornax句柄at
1条回答
网友
1楼 · 发布于 2024-04-25 21:40:12

包含数据点的PathCollectionax.get_children()[0]。调用.get_array()的结果是None(不是空的),但这不会阻止您对PathCollection使用mplot3d。此代码适用于我:

tips = sns.load_dataset("tips")
ax = sns.swarmplot(x=tips["total_bill"])
tooltip = mpld3.plugins.PointLabelTooltip(ax.get_children()[0],
                                          labels=tips.total_bill.tolist())
mpld3.plugins.connect(plt.gcf(), tooltip)
mpld3.show()

做了一个Jupiter notebook只是为了好玩。你知道吗

相关问题 更多 >