来自Seaborn教程我绘制了一个图:
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.swarmplot(x=tips["total_bill"])
现在,我想拥有包含使用MPLD3在Interactive中的数据的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
是ax.get_children()[0]
。调用.get_array()
的结果是None
(不是空),但这不会阻止您使用PathCollection
的USIMG 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()
只是为了娱乐而制作的木星笔记本。