-1

PDF from histogram data PDF from histogram data

I am trying to get a PDF with a smoother outline. Also, the area under the curve must be filled. How can I get the curve of best fit for this?

This is the code I have used.

plt.hist(
    data,
    range=[0, 60],
    bins=60,
    density=True,
    label="In bulk",
    histtype="stepfilled",
    alpha=0.5,
)
Pawel Kam
  • 1,684
  • 3
  • 14
  • 30
  • Think you want to plot a kernel density estimate rather than a histogram. Check out the seaborn package for an easy version, or you need to use scipy to estimate it then plot manually. See https://stackoverflow.com/q/4150171/1358308 – Sam Mason Mar 13 '23 at 11:17
  • Does this answer your question? [How to create a density plot in matplotlib?](https://stackoverflow.com/questions/4150171/how-to-create-a-density-plot-in-matplotlib) – Sam Mason Mar 13 '23 at 18:51

1 Answers1

0

Your description is vague, but as far as I understood you want to fill everything under the line each bar is spanning!

You can use .fill_between for that! Refer to the documentation.

J. M. Arnold
  • 6,261
  • 3
  • 20
  • 38