【发布时间】:2021-01-05 05:31:38
【问题描述】:
我正在尝试使用 displot 绘制平均线。我正在尝试复制 this 示例,但出现错误。
from matplotlib import pyplot
g = sns.displot(data=df, x='age', kind="kde", hue="attrition", palette="crest", fill=True,alpha=.7, linewidth=0,)
g.fig.set_figwidth(15)
g.fig.set_figheight(5)
kdeline = g.lines[0]
mean = x.mean()
height = np.interp(mean, kdeline.get_xdata(), kdeline.get_ydata())
g.vlines(mean, 0, height, color='crimson', ls=':')
g.set_ylim(ymin=0)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-26-86084b5eb03a> in <module>
5 g.fig.set_figwidth(15)
6 g.fig.set_figheight(5)
----> 7 kdeline = g.lines[0]
8 mean = x.mean()
9 height = np.interp(mean, kdeline.get_xdata(), kdeline.get_ydata())
AttributeError: 'FacetGrid' object has no attribute 'lines'
【问题讨论】:
标签: python python-3.x matplotlib seaborn