2014-06-19 24 views
2

我有以下代碼UnboundLocalError在ggplot 0.5

p = ggplot(aes(x='DHT temp',y='temp3'), data=data) 
p + geom_point(alpha=0.1, size=10) + scale_x_continuous(limits=(20,30)) + 
scale_y_continuous(limits=(0,170)) + theme_bw()\ 
+ geom_abline(intercept=20) 

,我得到以下錯誤:

<repr(<ggplot.ggplot.ggplot at 0x607a3d0>) 
failed: UnboundLocalError: local variable 'x' referenced before assignment> 

一些示例數據

 HIH  DHThum DHTtemp temp1 temp3 
0 350  67.7 22.7 328  148 
1 356  67.9 22.7 328  149 
2 365  67.8 22.7 328  148 
3 349  67.9 22.6 327  148 
4 348  68.0 22.6 328  149 
+0

嗯。你可以試試: ''' 進口ggplot 打印ggplot .__ version__ ''' 也許粘貼你的數據的幾行也將有助於重現你看到過這個問題。 – hernamesbarbara

+0

ggplot版本0.5.0 – Hugo

+0

這是上面完成的。謝謝 – Hugo

回答

1

大。 Thx發佈一些數據。不幸的是,我無法在我的結尾重新創建問題。

from ggplot import * 
import pandas as pd 
import re 

data = """ 
    HIH  DHThum DHTtemp temp1 temp3 
0 350  67.7 22.7 328  148 
1 356  67.9 22.7 328  149 
2 365  67.8 22.7 328  148 
3 349  67.9 22.6 327  148 
4 348  68.0 22.6 328  149 
""" 

data = [re.split('\s+', line) for line in data.split('\n') if line] 

headers, data = data[0], data[1:] 
headers[0] = 'index_col' 

df = pd.DataFrame(data, columns=headers) 
df = df.astype(float) 

p = ggplot(aes('DHTtemp', 'temp3'), data=df) 

p = p + geom_point(alpha=0.1, size=10) + \ 
    scale_x_continuous(limits=(20,30)) + \ 
    scale_y_continuous(limits=(0,170)) + theme_bw() + \ 
    geom_abline(intercept=20) 

ggsave('plot.png', p) 

情節爲我呈現,沒有例外,你看到。當然,因爲這只是前5排,情節並沒有真正描述任何有趣的事情。

enter image description here

將繼續挖掘,問了幾個人在我的球隊,如果他們知道這是怎麼回事。