Search code examples
pythonpandaspython-ggplot

Is there a way to plot a pandas series in ggplot?


I'm experimenting with pandas and non-matplotlib plotting. Good suggestions are here. This question regards yhat's ggplot and I am running into two issues. Plotting a series in pandas is easy.

frequ.plot()

I don't see how to do this in the ggplot docs. Instead I end up creating a dataframe:

cheese = DataFrame({'time': frequ.index, 'count' : frequ.values})
ggplot(cheese, aes(x='time', y='count')) + geom_line()

I would expect ggplot -- a project that has "tight integration with pandas" -- to have a way to plot a simple series.

Second issue is I can't get stat_smooth() to display when the x axis is time of day. Seems like it could be related to this post, but I don't have the rep to post there. My code is:

frequ = values.sampler.resample("1Min", how="count")
cheese = DataFrame({'time': frequ.index, 'count' : frequ.values})
ggplot(cheese, aes(x='time', y='count')) + geom_line() + stat_smooth()

Any help regarding non-matplotlib plotting would be appreciated. Thanks! (I'm using ggplot 0.5.8)


Solution

  • This is more of a workaround but you can use qplot for quick, shorthand plots using series.

    from ggplot import *
    qplot(meat.beef)