4

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?

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Piotr Zduniak
  • 97
  • 2
  • 8
  • 1
    I can't help you wit the `ggplot` stuff, unfortunately. But I thought you might like to know that with a current version of pandas, you can simply do `pd.read_sql(sql, conn)`. Not terribly important, but it's nice. – Paul H Dec 06 '13 at 18:33
  • my guess is that its an incompatibility in the date format. can you post some of the `lng` dataframe? – zach Dec 06 '13 at 20:04
  • Somehow code works in production on an Ubuntu Server, but doesn't in VM on Ubuntu. I have **no idea** what's happening. – Piotr Zduniak Dec 06 '13 at 22:51
  • There have been a lot of updates to ggplot since this was originally asked. Is this still an issue? – Greg Apr 24 '14 at 15:22

1 Answers1

2

Should be fixed as per these issues:

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

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

Greg
  • 1,070
  • 11
  • 16