Python 将第二个轴添加到图形中
我尝试在Python中使用ggplot。但我在右边绘制第二个轴时遇到了问题。现在我生成这样的图像 代码为:Python 将第二个轴添加到图形中,python,r,pandas,matplotlib,ggplot2,Python,R,Pandas,Matplotlib,Ggplot2,我尝试在Python中使用ggplot。但我在右边绘制第二个轴时遇到了问题。现在我生成这样的图像 代码为: ( ggplot(t, aes('app_dt', y='distr', fill='temp')) \ + geom_col() \ + geom_line(t, aes('app_dt', y=..., group=1), colour='red') \ + geom_point(t, aes('app_dt', y=...), size=2, fil
(
ggplot(t, aes('app_dt', y='distr', fill='temp')) \
+ geom_col() \
+ geom_line(t, aes('app_dt', y=..., group=1), colour='red') \
+ geom_point(t, aes('app_dt', y=...), size=2, fill='white') \
+ geom_text(...) \
+ scale_y_continuous(label='percent') \
+ geom_text(aes(label=round(t['distr'] * 100, 1).astype(str) + '%'), size=7, position=position_stack(vjust=0.5)) \
+ scale_fill_brewer(palette='PuBuGn')
)
但我需要这样的东西
因此,问题是:
提前谢谢你 选中此项可使用ggplot在右侧添加第二个轴。此外,您可以使用
scale\u fill\u manual
手动设置颜色,而不是scale\u fill\u brewer
我搜索并发现,在ggplot提供的R第二轴和第一轴中,必须与某些公式相连接。更重要的是,这个R函数对我不起作用:scale\u y\u continuous(labels=scales::percent,sec.axis=sec\u axis(~.*psi\u plot\u lim,labels=scales::percent)),所以问题被打开了。我的意思是在Python中我没有sec.axis选项