0
import matplotlib.image as mpimg
from scipy.spatial import distance
import matplotlib.patches as mpatches
import pylab
import matplotlib.mlab as mlab
import scipy.stats as ss

fig = plt.figure(num=None, figsize=(9, 7), facecolor='w', edgecolor='k')   
ax = fig.add_subplot(111)
plt.hist(h, bins=30, normed=True)    #h is the data

right now my plot looks like this: enter image description here

I want to add a trend line to reflect the histogram. To reflect the peak of each bin. So tried what fuglede suggested, using seaborn, I got something that is really weird. enter image description here

I dont know why suddenly with the seaborn imported, my plot has those weird grey grids going on. I'm using Sypder btw. Second, I want to have a smooth like, not like the one I have right now just going up and down.

JY078
  • 393
  • 9
  • 21
  • Closed to the other question because `displot` has been removed from seaborn. Answers in the duplicate already discuss the updated opitons. – Trenton McKinney May 25 '23 at 21:54

1 Answers1

2

It sounds like you might be looking for something like a kernel density estimate. An off-the-shelf KDE calculator/plotter with a simple API is available in Seaborn.

import numpy as np
import seaborn as sns

data = np.random.normal(0, 1, 100)
sns.distplot(data)

enter image description here

fuglede
  • 17,388
  • 2
  • 54
  • 99