2017-01-31 4 views
1

ggplot을 사용하여 플롯을 만들려고하고 있는데 왜이 오류가 발생하는지 잘 모르겠습니다. 여기 코드는 다음과 같습니다ggplot (python) 오류 받기 NameError : name 'stat_function'이 정의되지 않았습니다.

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 

내가이 오류를 받고 있어요 이유를 모르겠어요. 어떤 아이디어? 나는 똑같은 예를 code

에서 똑같은 오류가 발생했습니다 파이썬 3.5.2 및 ggplot 버전 0.11.5

답변

1

를 사용하여 ggplot 라이브러리는 리팩토링을 통해 갔다 보인다 있어요.

pip install -U git+https://github.com/yhat/[email protected] 

다음

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)") 

그것은 때 나는 오류를 가지고

enter image description here

+0

포스트에서와 동일한 수치를 생성합니다 :

해당 버전의 사용을 설치하려면 jupyt에서'pip install -U git + https : // github.com/yhat/ggpy.git @ v0.6.6'을 다운로드하려고했습니다. 어. 내가 뭘 잘못하고 있을지 모르겠다. '오류 : 파일 "", 줄 1 pip install -U git + https : //github.com/yhat/[email protected] ^ 구문 오류 : 잘못된 구문' –

+0

명령 줄에서 해당 명령을 실행하고 노트북에서는 실행하지 마십시오. –

관련 문제