Closed dalanmiller closed 8 years ago
Also had this. Was a problem with cairo. Try:
sudo apt-get install libffi-dev
sudo pip install cairocffi
So the fix is to replace this code in ggplot.ggplot.py (https://github.com/yhat/ggplot/blob/master/ggplot/ggplot.py#L550)
env = EvalEnvironment.capture(eval_env=(aes.__eval_env__ or 1))
# add factor as a special case
- env.add_outer_namespace({"factor":factor})
+ env = env.with_outer_namespace({"factor":factor})
But this also needs an a strict version dependency on patsy 4.0+
@acconsta Didn't work for me ;( and already had it installed
@JanSchulz After making that one line change I then get this error:
TypeError: pivot_table() got an unexpected keyword argument 'rows'
Yea, thats another thing you need to change: https://github.com/yhat/ggplot/issues/428
cols
-> columns
rows
-> index
@janschulz do you know if there's a PR to fix this just yet?
I'm surprised more people aren't having this issue?
Th eval env problem from this issue? No, not that I know. Maybe it is fixed in the big rewrite (#360), but nothing in master... The index/row problem is in in PR https://github.com/yhat/ggplot/pull/430, but unmerged.
I don't understand how people aren't having this issue on the simplest of examples in ggplot
? I also tried your suggestion @acconsta to no avail.
In [1]: from ggplot import *
In [2]: ggplot(aes(x="factor(cyl)"), data=mtcars) + geom_bar()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-97dacbd575ef> in <module>()
----> 1 ggplot(aes(x="factor(cyl)"), data=mtcars) + geom_bar()
/usr/local/lib/python3.5/site-packages/ggplot/ggplot.py in __init__(self, aesthetics, data)
64
65 self.aesthetics = aesthetics
---> 66 self.data = _apply_transforms(data, self.aesthetics)
67
68 # defaults
/usr/local/lib/python3.5/site-packages/ggplot/ggplot.py in _apply_transforms(data, aes)
548 env = EvalEnvironment.capture(eval_env=(aes.__eval_env__ or 1))
549 # add factor as a special case
--> 550 env.add_outer_namespace({"factor":factor})
551 try:
552 new_val = env.eval(name, inner_namespace=data)
AttributeError: 'EvalEnvironment' object has no attribute 'add_outer_namespace'
This is in Python 3.5.0 using ipython 4.0.0.
Here's my pip freeze
:
appnope==0.1.0
brewer2mpl==1.4.1
decorator==4.0.4
Flask==0.10.1
ggplot==0.6.8
gnureadline==6.3.3
google-api-python-client==1.4.2
gunicorn==19.3.0
httplib2==0.9.2
ipython==4.0.0
ipython-genutils==0.1.0
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
matplotlib==1.4.3
nose==1.3.7
numpy==1.10.1
oauth2client==1.5.1
pandas==0.17.0
path.py==8.1.2
patsy==0.4.0
pexpect==4.0.1
pickleshare==0.5
ptyprocess==0.5
py-stackexchange==2.2.4
pyasn1==0.1.9
pyasn1-modules==0.0.8
pyparsing==2.0.3
python-dateutil==2.4.2
pytz==2015.6
requests==2.7.0
rethinkdb==2.1.0.post2
rsa==3.2
scipy==0.16.0
simplegeneric==0.8.1
simplejson==3.8.0
six==1.10.0
slackclient==0.16
statsmodels==0.6.1
traitlets==4.0.0
uritemplate==0.6
websocket-client==0.32.0
Werkzeug==0.10.4
wheel==0.24.0
This is already fixed in https://github.com/has2k1/ggplot/pull/1, I think..
So any solution to this bug yet? I edited ggplot.py as suggested but no luck.
Not sure if this is relevant to your error, but I got this error when referencing a string as a list index in my plotting function:
def plotdgg(x, y, df):
ggplot(aes(x=x[0], y=y), data=df)
produced this error: File "/usr/local/lib/python2.7/dist-packages/ggplot/ggplot.py", line 66, in init self.data = _apply_transforms(data, self.aesthetics) File "/usr/local/lib/python2.7/dist-packages/ggplot/ggplot.py", line 550, in _apply_transforms env.add_outer_namespace({"factor":factor}) AttributeError: 'EvalEnvironment' object has no attribute 'add_outer_namespace'
Using this function call, corrected the error:
def plotdgg(x, y, df):
ggplot(aes(x=x, y=y), data=df)
But a string is supposed to work. Extremely annoying. Any solution yet?
still wating
I got the same error
AttributeError Traceback (most recent call last)
Getting the same error on a time series. Any fix? Plotting on dataframe with the date indexed as a time series throws an error.
ggplot(aes(x='as_of', y='likes', colour='Name'), data=ts) + geom_line() + stat_smooth(span=0.10)
However, plotting the same data on the data without being indexed by date, works.
ggplot(aes(x='as_of', y='likes', colour='Name'), data=df) + geom_line() + stat_smooth(span=0.10)
jupyter notebook, python 2.7, ubuntu
The fix is the comment above: https://github.com/yhat/ggplot/issues/457#issuecomment-148017190 or in https://github.com/yhat/ggplot/pull/462
data =[[1, 2]]
from pandas import DataFrame
powd = DataFrame(data, columns=['TIME', 'Watts'])
from ggplot import *
gg = ggplot(aes(x='date', y='beef'), data=powd) + \
geom_point(color='lightblue') + \
stat_smooth(span=.15, color='black', se=True) + \
ggtitle("Beef: It's What's for Dinner") + \
xlab("X") + \
ylab("Y")
#ggsave(gg, filename='test.png')
gg.draw()
ggsave(filename='test.png')
crashes with
Traceback (most recent call last):
File "test.py", line 11, in <module>
xlab("X") + \
File "/usr/local/lib/python3.4/dist-packages/ggplot/ggplot.py", line 66, in __init__
self.data = _apply_transforms(data, self.aesthetics)
File "/usr/local/lib/python3.4/dist-packages/ggplot/ggplot.py", line 550, in _apply_transforms
env.add_outer_namespace({"factor":factor})
AttributeError: 'EvalEnvironment' object has no attribute 'add_outer_namespace'
https://github.com/yhat/ggplot/issues/457#issuecomment-147898808 failed to improve the situation.
Just loaded up ggplot
to try and make some graphs, and got this error again, which I Google'd to come back to this issue I created six months ago :cry:.
@JanSchulz did you stop seeing this issue?
@dalanmiller No, I still have it when I install ggplot...
IMO ggplot for python is dead :-/
@JanSchulz has something replaced it?
matplotlib itself has now support for a data argument (plt.scatter(x="xvar", y="yvar", data=pd_dataframe)
) and there is seaborn...
There is also now a solid r support for the jupyter notebook (irkernel), so plotting ggplot2 in the notebook is possible.
Maybe in the future @has2k1 will finish his rewrite (#360)...
Matplotlib >= 1.4 also has matplotlib.style.use('ggplot')
what nicely solves problem of hilariously ugly graphs.
Man, that sucks. GoG notation is so useful. And MPL will probably never have support for facetting and maybe a bunch of other stuff...
Same exact error when I'm just doing the first line of code from the bar chart example: http://ggplot.yhathq.com/docs/geom_bar.html
I also don't understand how more people are not getting the same error .
Starting to think it may be worth the hassle to use python to format my dataframe and then pipe it to R and work from ggplot there.
I think ggplot is just dead. I switched to pandas/seaborn.
This is fixed in the next release which will happen later this week https://github.com/yhat/ggplot/tree/overhaul
Why not take #360 (or better https://github.com/has2k1/ggplot/commits/rewrite) and go from there? From looking at the code, a lot of things work there and it comes very close to how ggplot works underneath (e.g. themes and how to compose new ones)
Re stat_indentity:
they're gone. They didn't even come close to working (also what does stat_identity even do) so they're gone.
From http://docs.ggplot2.org/0.9.3.1/geom_bar.html
# When the data contains y values in a column, use stat="identity"
library(plyr)
# Calculate the mean mpg for each level of cyl
mm <- ddply(mtcars, "cyl", summarise, mmpg = mean(mpg))
ggplot(mm, aes(x = factor(cyl), y = mmpg)) + geom_bar(stat = "identity")
fixed in 0.9.3
Just installed yhat Rodeo and tried to create a graph with ggplot (I also get this error when tried in iPython however):
But I get this error below
Any thoughts?