如何解决plotnine 问题使用 stat_smooth 和 geom_path
Stackoverflow 社区,
我目前在 python 中使用 plotnine 时遇到问题。 我的代码如下:
from plotnine import *
from plotnine.data import mpg
%matplotlib inline
plot = (ggplot(result) +
aes(x = 'age',y = 'fa index',color='ID') +
geom_point(size = 2) +
geom_path() +
stat_smooth(method='lm') +
aes(group = 'Trained_yung') + #line of best fit by group
ylab("FA index") +
xlab("Age (days)") +
theme_bw())
plot.save('filename.pdf',height=8,width=8)
"result" 是带有我的结果的 Pandas 数据框。
如果删除stat_smooth:
plot = (ggplot(result) +
aes(x = 'age',color='ID') +
geom_point(size = 2) +
geom_path() +
ylab("FA index") +
xlab("Age (days)") +
theme_bw())
plot.save('filename.pdf',width=8)
我有:
so I deduced that stat_smooth added these weird links between my points
解决方法
https://github.com/has2k1/plotnine/issues/480
stat_smooth 不会将任何点链接在一起。 问题是您正在添加另一个美学映射!
stat_smooth(method='lm') + aes(group = 'Trained_yung') + #line of best fit by group
一个好的脚本是:
import pandas as pd
import numpy as np
from pandas.api.types import CategoricalDtype
from plotnine import *
from plotnine.data import mpg
%matplotlib inline
plot = (ggplot(result) +
aes(x = 'age',y = 'fa index',color='ID') +
geom_point(size = 2) +
geom_path() +
stat_smooth(method='lm',group = 'Trained_yung') +
ylab("FA index") +
xlab("Age (days)") +
theme_bw())
plot.save('filename3.pdf',height=8,width=8)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。