问题
That's 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 is what the code generates:
result http://zduniak.net/wV9S6
The history table has 3 columns:
- time - datetime
- players - integer
- servers - integer
What I want is two smooth red lines drawn over black and orange ones. Somehow stat_smooth doesn't work at all. How can I make it work?
回答1:
Should be fixed as per these issues:
https://github.com/yhat/ggplot/pull/43
https://github.com/yhat/ggplot/pull/170
来源:https://stackoverflow.com/questions/20427050/how-do-i-make-stat-smooth-work-in-ggplot-python