How to make stat_smooth work in ggplot-python?

What is my code:

import pandas as pd
import pandas.io.sql as sqlio
from ggplot import *
from db import conn

sql = "SELECT * FROM history WHERE time > (NOW() - INTERVAL '1 day')::date"
df = sqlio.read_frame(sql, conn)
conn.close()

lng = pd.melt(df[['time', 'players', 'servers']], id_vars='time')
plt = ggplot(aes(x='time', y='value', colour='variable'), data=lng) + \
        geom_line() + \
        stat_smooth(colour='red', se=True) + \
        ggtitle('Players and servers online over last 24h') + \
        xlab("Time of the day") + \
        ylab("Amount")
ggsave(filename="day.svg", plot=plt)

This code generates:

result of http://zduniak.net/wV9S6

There are 3 columns in the history table:

  • time - date-time
  • players are integer
  • servers - integer

I want two smooth red lines drawn over black and orange. Somehow stat_smooth doesn't work at all. How can I make it work?

+4
source share
1 answer
+2
source

All Articles