Hugo
Hugo

Reputation: 1698

UnboundLocalError in ggplot 0.5

I have the following code

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)

and I get the following error:

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

some sample 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

Upvotes: 2

Views: 70

Answers (2)

Jan Katins
Jan Katins

Reputation: 2319

This was a bug in ggplot which has been fixed in version 0.5.8.

Upvotes: 3

hernamesbarbara
hernamesbarbara

Reputation: 7018

Great. Thx for posting some data. Unfortunately, I'm not able to recreate the issue on my end.

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)

The plot renders for me without the exception you're seeing. Of course, since this is only the top 5 rows, the plot doesn't really describe anything interesting.

enter image description here

Will keep digging and ask a few people on my team if they know what's up.

Upvotes: 1

Related Questions