график распределения морских свинок добавить метку для подсчета на гистограмму бин - PullRequest
0 голосов
/ 08 мая 2019

Как я могу заставить seaborn добавить метку для графика распределения, которая содержит количество элементов в корзине?

import seaborn as sns, numpy as np
sns.set(); np.random.seed(0)
x = np.random.randn(100)
ax = sns.distplot(x)

следует вместо метки распределения по умолчанию добавить метку для каждой панели: enter image description here

1 Ответ

1 голос
/ 08 мая 2019

Примерное решение может быть:

import seaborn as sns, numpy as np
import matplotlib.pyplot as plt

# add the following line if working on jupyter notebook
%matplotlib inline

sns.set()
np.random.seed(0)
x = np.random.randn(100)
ax = sns.distplot(x)

s = 0

for p in ax.patches:
    s+= p.get_height()

for p in ax.patches: 
    ax.text(p.get_x() + p.get_width()/2.,
            p.get_height(),
            '{}'.format(int(p.get_height()*100/s)), 
            fontsize=14,
            color='red',
            ha='center',
            va='bottom')
plt.show()

, и вы получите:

enter image description here

...