【问题标题】:Graph histogram and normal density with pandas使用 pandas 绘制直方图和正态密度
【发布时间】:2014-05-03 14:33:12
【问题描述】:

我正在寻找像这样的 serie df 绘制法线密度和直方图密度,但没有实现。 像下面的链接 http://hypertextbook.com/facts/2007/resistors/histogram.gif

如何使用 DataFrame 对象做到这一点?

>>> fd
Scenario
s0000      -2.378963
...
s0999       1.368384
Name: values, Length: 1000, dtype: float64
>>> fd.hist(bins=100)

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    我认为你可以先绘制像 fd.hist() 这样的直方图

    然后拟合法线密度,用matplotlob绘制,请参考:

    Fitting a histogram with python

    【讨论】:

    • 当然可以,但没有自动方式?我认为这是一种普遍的需求
    【解决方案2】:
    fig = plt.figure()
    ax = fig.add_subplot(111)
    fd.hist(ax=ax, bins=100)
    ax1 = ax.twinx()
    fd.plot(kind="kde", ax=ax1, legend=False )
    

    改编自https://stackoverflow.com/a/26913361/841830,其中显示了两个直方图和两个密度图的更复杂情况。

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 1970-01-01
      • 2013-03-02
      • 2017-06-08
      • 1970-01-01
      • 2014-04-10
      • 2019-11-04
      • 2021-05-04
      • 2018-06-30
      相关资源
      最近更新 更多