Python 将第二个轴添加到图形中

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

我尝试在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, 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')
)
但我需要这样的东西

因此,问题是:

  • 如何添加第二个轴,哪些值与红色(蓝色)线中的percent值相连接

  • 我应该使用哪个功能将颜色托盘更改为自定义

  • 如何对轴进行百分比缩放


  • 提前谢谢你

    选中此项可使用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选项