'Secondary y-axis is not plotting

I created a bar plot and now I want to add a secondary y-axis as a line using 'Recovered' from my pivot table. Unfortunately, the data for secondary y-axis is not showing but the axis is displaying correctly.

Can someone help me with this? Thank you!

pivot['Unrecovered'] = pivot['Claim'] - pivot['Paid']
pivot['Recovered'] = (pivot['Paid'] / pivot['Claim'])*100
pivot

pivot output:

Fiscal Year Claim Paid Unrecovered Recovered
2018 788,602.37 610,283.05 178,319.32 77.39
2019 9,870,246.71 7,834,106.99 2,036,139.72 79.37
2020 7,661,541.11 5,839,581.89 1,821,959.22 76.22
2021 6,641,099.86 4,641,853.93 1,999,245.93 69.90
2022 3,124,225.48 700,148.52 2,424,076.96 22.41
# plot pivot table with secondary y-axis showing % Recovered

pivot.plot(y = ['Paid','Unrecovered'],
       kind='bar',
       rot=0,
       stacked = True,
       ylabel ='Amount ($)')
plt.ticklabel_format(style='plain', axis='y')
ax = pivot["Recovered"].plot(secondary_y = True, 
                         color = 'k',
                         marker = 'o')
ax.set_ylabel("Recovered")
ax.set_ylim(0,100)
plt.show()

Output : Recovered plot



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source