// &&&&&&
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))