16
votes

I've just started to learn to use python. I'm using anaconda python 3.5 and Rodeo to do a simple ggplot.

from ggplot import *
df=pd.DataFrame({"Animal":["dog","dolphin","chicken","ant","spider"],"Legs":[4,0,2,6,8]})
p=ggplot(df, aes(x="Animal", weight="Legs")) + geom_bar(fill='blue')
p
ggsave("test.png",p)

Everything works fine before the 5th line. I got the plot as I wanted. But I got an error when I tried to save the plot:

NameError: name 'ggsave' is not defined

It seems that there's no ggsave function in ggplot module? The ggplot version is 0.11.1. Am I missing something here?

1
Use 'p.save("test.png")' - rfkortekaas
@rfkortekaas I have the same problem - your solution works, I am just not able to specify dpi and format among other things. Do you know what the solution is using ggsave? I have a NameError saying ggsave is not defined. - Justin
@Justin your question is not related to this. Please create your own. - rfkortekaas
Can you give the output of 'ggsave' in dir(ggplot) just prior to calling ggsave? I expect that the result will be True. If not, we know that the problem is in your import statement somehow, since ggsave is definitely an imported symbol from the ggplot module according to its documentation. - Matthew Cole

1 Answers

8
votes

You can use:

p.save('test.png')