0
This example,扩展here,显示了如何标记Matplotlib中的柱状图;可以使用类似的想法来标记箱形图。它依赖于知道条形图的x和y坐标,它们是由barplot函数返回的。我怎么能为Seaborn box plots做同样的事情?不幸的是,Seaborn不会返回这些坐标。Seaborn boxplot中盒子的坐标
This example,扩展here,显示了如何标记Matplotlib中的柱状图;可以使用类似的想法来标记箱形图。它依赖于知道条形图的x和y坐标,它们是由barplot函数返回的。我怎么能为Seaborn box plots做同样的事情?不幸的是,Seaborn不会返回这些坐标。Seaborn boxplot中盒子的坐标
你可以绕过一些找到它们,但它不漂亮。
sns.boxplot
返回matplotlib
箱子绘制的轴实例。
这些框创建为matplotlib.patches.PathPatch
实例。
我们可以发现这些情况下,像这样:
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
for c in ax.get_children():
if type(c) == matplotlib.patches.PathPatch:
print c.get_extents()
这将打印盒的BBox
,在这个例子:
Bbox(x0=92.4, y0=116.996, x1=191.6, y1=162.242666667)
Bbox(x0=216.4, y0=114.957333333, x1=315.6, y1=171.6)
Bbox(x0=340.4, y0=125.576, x1=439.6, y1=189.141333333)
Bbox(x0=464.4, y0=131.926666667, x1=563.6, y1=194.172)