0

I would like to display the X value in my histogram at which the maximum Y values are present. I followed the example on the page: Find the x value corresponding to a histogram max

and wrote this:

def Plot_show_us(dfus, dfdus, dfnus):
    x = dfus['O18ad']
    bins=[-22,(...),22] # normaly here are a lot of Bins 
    n, b, patches =plt.hist(x, bins, alpha=0.65, label='old')
    bin_max = np.where(n == n.max())
    print('maxbin'), b[bin_max][0]
    plt.legend(loc='upper right')

However, I couldn't get any output! What am I doing wrong (I think this is a beginner's mistake)?

my output:

Plot_show_us(dfus, dfdus, dfnus)
maxbin
Weiss
  • 176
  • 2
  • 16
  • You must return a variable if you want the function get that as an output. `return maxbin` – Ali_Sh Jul 01 '22 at 10:50
  • Or, just to display, change the `print` statement to: `print('maxbin', b[bin_max][0])`. Notice the `)` moves to the right. – S3DEV Jul 01 '22 at 12:53

1 Answers1

0
print('maxbin: %i'%b[bin_max][0])

or

print('maxbin: '+str(b[bin_max][0]))
  • 1
    Not needed. OP's code has a typo, just `print('maxbin', b[bin_max][0])` will work fine. – S3DEV Jul 01 '22 at 12:51