在swarmplot上绘制另一点 [英] Plot another point on top of swarmplot
本文介绍了在swarmplot上绘制另一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想像这样在swarmplot上绘制一个突出显示的点
I want to plot a "highlighted" point on top of swarmplot like this
swarmplot没有y轴,所以我不知道如何绘制该点。
The swarmplot don't have the y-axis, so I have no idea how to plot that point.
import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.swarmplot(x=tips["total_bill"])
推荐答案
了解要突出显示的数据点的索引后,它应该可以工作-尽管如果在单个轴
实例上有多个swarmplot,它将变得稍微复杂一些。 / p>
This approach is predicated on knowing the index of the data point you wish to highlight, but it should work - although if you have multiple swarmplots on a single Axes
instance it will become slightly more complex.
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.swarmplot(x=tips["total_bill"])
artists = ax.get_children()
offsets = []
for a in artists:
if type(a) is matplotlib.collections.PathCollection:
offsets = a.get_offsets()
break
plt.scatter(offsets[50,0], offsets[50,1], marker='o', color='orange', zorder=10)
这篇关于在swarmplot上绘制另一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文