Getting ggplot (python) error NameError: name 'stat_function' is not defined

Getting ggplot (python) error NameError: name 'stat_function' is not defined

我正在尝试使用 ggplot 绘图,但不确定为什么会出现此错误。这是代码:

from ggplot import *

ggplot(counts, aes(x='pred_prob',y='true_prob',size='count')) + \
    geom_point(color='blue') + \
    stat_function(fun=lambda x: x, color='red') + \
    xlim(-0.05,  1.05) + ylim(-0.05,1.05) 

这是我得到的错误:

NameError                                 Traceback (most recent call last)
<ipython-input-71-fdefd49237a1> in <module>()
  2 
  3 baseline = np.mean(is_churn)
----> 4 ggplot(counts, aes(x='pred_prob',y='true_prob',size='count')) + geom_point(color='blue') + stat_function(fun=lambda x: x, color='red') + xlim(-0.05,  1.05) + ylim(-0.05,1.05)
NameError: name 'stat_function' is not defined

我不确定为什么会收到此错误。有任何想法吗?我正在使用 python 3.5.2 和 ggplot 版本 0.11.5

我从同一个例子中得到了同样的错误 code

ggplot 库似乎经历了重构。

要安装该版本,请使用:

pip install -U git+https://github.com/yhat/ggpy.git@v0.6.6

然后

from ggplot import *
from ggplot.stats.stat_function import stat_function # added line
import pandas as pd
%matplotlib inline

ggplot(pd.DataFrame({'x':[0,500]}), aes(x='x')) + \
    stats.stat_function(fun = lambda x: 50. / (x + 50.)) + \
    ggtitle("Epsilon decay over time") + \
    xlab("amount of feedback") + ylab("epsilon (probability of testing)")

它将产生与 post

中相同的数字