0

I am trying to add labels to my below Bar chart attached as image and I am using the below code Could someone please help?

#Count of Labels
Count = data.groupby(['kmeans']).size().reset_index(name='counts')
Count
Count.plot(x="kmeans", y=["counts"], kind="bar")

plt.title("Clustering Output grouped by Labels")
plt.xlabel("Labels_Predicted")
plt.ylabel("Total data points")
plt.savefig('label_count_img.png', dpi=1200)

enter image description here

SMR
  • 401
  • 4
  • 15
  • Does this answer your question?:https://stackoverflow.com/questions/28931224/adding-value-labels-on-a-matplotlib-bar-chart – JacksonPro Dec 17 '20 at 04:20
  • The Matplotlib documentation includes [an example on how to do this](https://matplotlib.org/gallery/lines_bars_and_markers/barchart.html). – Patrick FitzGerald Dec 19 '20 at 10:49

1 Answers1

0

I'm not exactly sure what you want to do, so I assumed you want to change the name for each bar.

I couldn't tell what your data was, so I just created my own data as an example. Anyways, this is how I did it:

import matplotlib.pyplot as plt

x = ['Label 1', 'Label 2']
data = [419, 337]

plt.bar(x, data)
plt.title("Clustering Output grouped by Labels")
plt.xlabel("Labels_Predicted")
plt.ylabel("Total data points")

plt.show()

plt.savefig('label_count_img.png', dpi=1200)
The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24
  • Hi,Thanks for your reply. The code I have pasted in my question works fine but I just want to show labels in the bars (419 in the first bar and 337 in the second bar) – SMR Dec 16 '20 at 21:45