matplotlib直方图与线

时间:2017-12-05 19:07:38

标签: python matplotlib histogram

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

现在我的情节看起来像这样: enter image description here

我想添加一条趋势线来反映直方图。反映每个箱子的峰值。所以尝试了fuglede所建议的,使用seaborn,我得到了一些非常奇怪的东西。 enter image description here

我不知道为什么突然进口了seaborn,我的情节有那些奇怪的灰色网格正在进行。我正在使用Sypder btw。 其次,我希望有一个平滑的,不像我现在刚刚上下的那个。

1 个答案:

答案 0 :(得分:0)

听起来你可能正在寻找像kernel density estimate这样的东西。 Seaborn中提供了一个带有简单API的现成KDE计算器/绘图仪。

import numpy as np
import seaborn as sns

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

enter image description here

相关问题