我如何在ggplot-python中进行stat_smooth工作? [英] How do I make stat_smooth work in ggplot-python?
本文介绍了我如何在ggplot-python中进行stat_smooth工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
将pandas导入为pd
将pandas.io.sql导入为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',color ='variable'),data = lng)+ \
geom_line() + \
stat_smooth(color ='red',se = True)+ \
ggtitle('过去24小时在线玩家和服务器')+ \
xlab当天)+ \
ylab(金额)
ggsave(文件名=day.svg,plot = plt)
这是代码生成的内容:
历史表ha s 3列:
- 时间 - 日期时间
- 玩家 - 整数
- 服务器 - 整数
我想要的是在黑色和橙色两条上画出两条平滑的红色线条。不知何故stat_smooth根本不起作用。
解决方案
应该根据以下问题解决问题:
https://github.com/yhat/ggplot/pull/43
https://github.com / yhat / ggplot / pull / 170
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?
解决方案
Should be fixed as per these issues:
https://github.com/yhat/ggplot/pull/43
https://github.com/yhat/ggplot/pull/170
这篇关于我如何在ggplot-python中进行stat_smooth工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文