1

This is a next-step on from an earlier question: Split series containing lists of strings into multiple columns

For charts created using the pandas .plot() method, is there a straightforward way of smoothing the plot of each data series, without breaking out into matplotlib? Or is it even possible with matplotlib, or should I be looking at different backends? I'd love to be able to use the pandas series without breaking out into building up .plot()s from scratch.

For reference, here's the pseudocode of a figure I'm plotting (datetime index):

In [*]: dataframe.groupby([dataframe.index.day,dataframe.index.hour]).sum().plot()

enter image description here

Context:

I understand there's a lot of discussion of using things like d3.js, and the developments towards using JS libraries and such in v2.0 over the coming months. If there's a current concensus on the 'best' way to create the kind of data visualisations that are commonly used on news websites and similar, I'd be happy to hear that and read up elsewhere.

4
  • 1
    What have you tried in the way of smoothing? Rolling average? Splines? Explicitly fitting to a known function? Commented Sep 6, 2013 at 2:56
  • Adding to what @tcaswell said, there are many different smoothing methods. pandas provides a few (rolling_mean, ewma to name a couple), there are many more in scipy (e.g., splines) and a few in statsmodels IIRC (LOWESS comes to mind). So, it really depends on what you're interested in doing with the smooth. Ultimately, you'll probably have to manipulate the plot produced by Series.plot(). Commented Sep 6, 2013 at 3:15
  • 2
    Here are the docs for the rolling_* functions in pandas. Commented Sep 6, 2013 at 3:18
  • As Phillip suggests, the simplest thing to do is probably to use a cubic spline as implemented in the scipy.interpolate.interp1d function. It should work well for the well-spaced data that you are showing here. There is a good example of the cubic spline here: docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html If you don't like the way that looks, then you can play around with the other methods, like a rolling mean. Commented Sep 6, 2013 at 5:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.