如何使 stat_smooth 在 ggplot-python 中工作?

2024-01-05

这是我的代码:

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)

这是代码生成的内容:

结果http://zduniak.net/wV9S6 http://zduniak.net/wV9S6

历史表有 3 列:

  • 时间 - 日期时间
  • 玩家 - 整数
  • 服务器 - 整数

我想要的是在黑色和橙色的线条上绘制两条平滑的红线。不知何故 stat_smooth 根本不起作用。我怎样才能让它发挥作用?


应根据以下问题进行修复:

https://github.com/yhat/ggplot/pull/43 https://github.com/yhat/ggplot/pull/43

https://github.com/yhat/ggplot/pull/170 https://github.com/yhat/ggplot/pull/170

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使 stat_smooth 在 ggplot-python 中工作? 的相关文章

随机推荐