[Python] Placing fitted curve as overlay to a histogram in an array of figures - Python...

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to add the line of a Gaussian fit to a histogram of data I have. I have set up an array of 3 plots in a row, the first two are images, the last is a histogram derived from the data, for which I have a Gaussian fit to it. All of the different datasets are good and accurate, I'm just having trouble putting the Gaussian fit over the top of my histogram. The current code replaces the histogram with the fit. Can't quite find what I am looking for in the normal places so any help would be appreciated. Thanks

    fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(60,20))
    ax1.imshow(img,cmap='viridis')
    ax1.set_title(plotTitle, fontsize=35)
    ax1.set_xticks([])
    ax1.set_yticks([])

    ax2.imshow(img2,cmap='magma')
    ax2.set_title(plotTitle2, fontsize=35)
    ax2.set_xticks([])
    ax2.set_yticks([])

    ax3.hist(histData, density=True, bins=nBins)
    ax3.plot(centBins,gauss_function(centBins,*pOpt),'ro:',label='fit')
    ax3.set_title('Intensity Histogram', fontsize=35)

    plt.show()

    Continue reading...

Compartilhe esta Página