Search code examples
pythonplothistogram

Create histogram with custom frequency values


I want to create a histogram plot with already known values of the frequency. The histogram is like - histogram plot. I can find the required 'number density'/y-axis values using web plot digitiser and now want to recreate this plot with the correct y-axis values of the number density of each particular bin. I have looked up tutorials of matplotlib and other related questions but it does not seem like it can be done with it. Any help/resource regarding this would be helpful, assuming if it is possible in python or even another language.

Edit - The output I am expecting should be somewhat like this (I know its quite crude) - output

The data I want to plot as a histogram could be assumed to be like -

4.2 nm to 4.3 nm - 0%(no values in this range)

4.3 nm to 4.4 nm - 33%

4.4 nm to 4.5 nm - 40%


Solution

  • Supposing you already have a list with the percentages in each bin and the bin centers

    import matplotlib.pyplot as plt
    binCenters = [4.2, 4.3, 4.4]
    percentages = [0, 33, 40]
    plt.bar(binCenters, percentages)
    plt.show()