How do I make stat_smooth work in ggplot-python?

﹥>﹥吖頭↗ 提交于 2020-01-03 17:06:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!