Python 如何使用seaborn.distplot绘制百分比?
有没有办法在distplot上绘制百分比而不是计数Python 如何使用seaborn.distplot绘制百分比?,python,pandas,seaborn,Python,Pandas,Seaborn,有没有办法在distplot上绘制百分比而不是计数 ax = sns.FacetGrid(telcom, hue='Churn', palette=["teal", "crimson"], size=5, aspect=1) ax = ax.map(sns.distplot, "tenure", hist=True, kde=False) ax.fig.suptitle('Tenure distribution in customer
ax = sns.FacetGrid(telcom, hue='Churn', palette=["teal", "crimson"], size=5, aspect=1)
ax = ax.map(sns.distplot, "tenure", hist=True, kde=False)
ax.fig.suptitle('Tenure distribution in customer churn', y=1, fontsize=16, fontweight='bold');
plt.legend();
您可以使用
norm\u hist=True
从:
标准历史记录:布尔,可选
如果为True,则直方图高度显示密度而不是计数。
如果绘制KDE或拟合密度,则意味着这一点
您可以选择一个条形图,并设置一个估计器,以百分比定义标准化:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame(dict(x=np.random.poisson(10, 1_000)))
ax = sns.barplot(x="x",
y="x",
data=df,
palette=["teal", "crimson"],
estimator=lambda x: len(x) / len(df) * 100
)
ax.set(xlabel="tenure")
ax.set(ylabel="Percent")
plt.show()
给予:
该方法给出了不需要的结果,例如在
sns中。distplot([1,2,2],norm\u hist=True)
y轴的值之和不等于1。类似的问答:很好的解释,但是norm\u hist=True
结果在这种情况下可能被认为是意外的。