user7648646
user7648646

Reputation:

How to display the values count on the bar chart

Can I please get some help on how I can include the counts on my bar chart. Thank you.

sns.countplot(data['target'])
plt.plot(0, label ="0 = No")
plt.plot(1, label ="1 = Yes")
plt.xlabel("Target")
plt.ylabel("count")
plt.title("Target vrs count")
plt.legend()
plt.show()

enter image description here

Upvotes: 4

Views: 5187

Answers (1)

Ami Tavory
Ami Tavory

Reputation: 76297

You can use matplotlib.text:

from matplotlib import pyplot as plt
data = pd.DataFrame({'target': [1, 1, 1, 0, 0]})
sns.countplot(data.target);
for v in [0, 1]:
    plt.text(v, (data.target == v).sum(), str((data.target == v).sum()));

enter image description here

Upvotes: 5

Related Questions