matplotlib twinx

// &&&&&&
An highlighted block
df_return_pur[‘trans_dt’]=pd.to_datetime(df_return_pur[‘trans_dt’].astype(“str”),errors = ‘coerce’)
df_return_pur[“purred”]=df_return_pur[“all_purchase_amount”]-df_return_pur[“redeem_alldeal_fund”]

for i in set(np.array(df_return_pur[‘fund_code’])):
df_fund=df_return_pur[ (df_return_pur[‘fund_code’]i) & (df_return_pur[‘amount_range’]“1k_5k”)].reset_index(drop=True)
df_fund=df_fund.sort_values(‘trans_dt’).reset_index(drop=True)

fig, ax1 = plt.subplots(figsize=(10,6))
ax1.set_xlabel('$Date$')

color1='tab:green'
color2='tab:purple'
color3='tab:red'
ax1.set_ylabel('$Amount$')
l1,=ax1.plot(df_fund["trans_dt"],df_fund["all_purchase_amount"],label="all_purchase_amount", color=color1)
l4,=ax1.plot(df_fund["trans_dt"],df_fund["redeem_alldeal_fund"],label="redeem_alldeal_fund", color=color2)
l2,=ax1.plot(df_fund["trans_dt"],df_fund["purred"],label="purred", color=color3)

ax1.plot(df_fund["trans_dt"],[0]*len(df_fund["trans_dt"]),color="k",alpha=0.5)

ax1.tick_params(axis='y')


plt.xticks(rotation=30)

ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis
color = 'tab:blue'
ax2.set_ylabel('$Return$', color=color)  
l3,=ax2.plot(df_fund["trans_dt"], df_fund["year_yield_rate"], color=color)
l5,=ax2.plot(df_fund["trans_dt"], df_fund["avg_return"], color=color,linestyle="--")
ax2.tick_params(axis='y', labelcolor=color)



plt.legend([l1,l2,l3,l4,l5],["all_purchase_amount","red_pur","return",'redeem_alldeal_fund',"avg_return"],loc=0)
plt.title('$fund\ %s$'%i)
fig.tight_layout()  # otherwise the right y-label is slightly clipped
plt.show()
fig.savefig("pic/fund_%s"%str(i))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值