【问题标题】:How do I make stat_smooth work in ggplot-python?如何使 stat_smooth 在 ggplot-python 中工作?
【发布时间】:2013-12-06 15:01:48
【问题描述】:

这是我的代码:

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)

这是代码生成的:

result http://zduniak.net/wV9S6

历史表有 3 列:

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

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

【问题讨论】:

  • 很遗憾,我无法帮助您了解 ggplot 的内容。但我想你可能想知道,使用当前版本的 pandas,你可以简单地做pd.read_sql(sql, conn)。不是很重要,但很好。
  • 我的猜测是它的日期格式不兼容。你能发布一些lng 数据框吗?
  • 不知何故,代码在 Ubuntu 服务器上的生产中工作,但在 Ubuntu 上的 VM 中不起作用。我不知道发生了什么。
  • 自从最初提出这个问题以来,ggplot 已经进行了很多更新。这仍然是个问题吗?

标签: python plot ggplot2 pandas python-ggplot


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 2021-06-09
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多