0

I try to place the raw counts of my histogram above or on the chart, i am quite new to python and already googled 6 hours for this problem, but i cant seem to get my script working!

Do you have any idea what i can do?

fig = plt.figure(figsize=(15/2.54,15/2.54))
ax2 = fig.add_subplot(111)
ASETvsRSET_flat = ASETvsRSET.ravel()
ax2.hist(ASETvsRSET_flat[~np.isnan(ASETvsRSET_flat)], color='lightskyblue',\
    bins=np.arange(rdiff_min,rdiff_max+1,1), edgecolor='k', normed=True )
ax2.set_xlabel(u'Räumungszeitdifferenz in min')
ax2.set_ylabel(r'p($\Delta_\mathrm{RDiff}$)')
ax2.axvline(0, ls='dashed', c='r')
nivramifu
  • 11
  • 2
  • If I can make a suggestion, why don't you actually place those values in a graphic table? I think it gets more organised than adding a lot of numbers in a graphic. – Chicrala Oct 25 '18 at 16:38
  • Possible duplicate of [matplotlib histogram: how to display the count over the bar?](https://stackoverflow.com/questions/39841733/matplotlib-histogram-how-to-display-the-count-over-the-bar) – jtweeder Oct 25 '18 at 17:18
  • how do i do that? – nivramifu Oct 25 '18 at 17:43
  • Possible duplicate of [Matplotlib - label each bin](https://stackoverflow.com/questions/6352740/matplotlib-label-each-bin) – Mr. T Oct 25 '18 at 18:58

1 Answers1

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

density, bins, _= plt.hist(data,density=True, bins=20)
count, _= np.histogram(data,bins)
for x,y, num in zip(bins, density, count):
    if num != 0:
    plt.text(x, y+0.05, num, fontsize=20)

sns.histplot(data=data,bins=20)
plt.show()

Try this way you will see counts in bottom inside the bins, and if font size to large or small just change fontsize=any as per required.

sanjugohel
  • 11
  • 3