我正在尝试在直方图中放置一个内核密度图,但是它不起作用。
这是我的代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
import seaborn as sns
from sklearn.neighbors import KernelDensity
fig, ax = plt.subplots()
n, bins, _ = ax.hist(df[column], bins=num_bins)
kde = KernelDensity(kernel='gaussian').fit(n[:,None])
data = np.exp(kde.score_samples(n[:,None]))
ax.plot(bins[:len(bins) - 1], data)
我的直方图如下所示。我无法获得内核密度图。