Put Values in Combination plot

35 views Asked by At

Using this example DataFrame:

d = {'date': ['202301', '202302', '202303', '202304', '202304'],
     'amount': [190080.10, 200010.20, 201085.50, 202550.54, 212035.80],
     'percent': [1.88, 1.89, 1.88, 1.91, 1.92]
    }
df = pd.DataFrame(data=d)
df

I've plotted the combination graph like that:

x = df['date']
y = df['amount']
y2 = df['percent']

fig = plt.figure(figsize=(8,4))
ax1 = plt.subplot(1,1,1)
plt.box(False)
plt.yticks([])
ax1.bar(x, y1, color = '#fed141')
ax1.set_ylim(0, y1.max() * 1.25)
ax1.set_axisbelow(True)

ax2 = ax1.twinx()
ax2.plot(x, y2, 'o-', color = '#90bac7', linewidth = 2)
ax2.set_ylim(0, y2.max() * 1.25)
plt.box(False) # remove bordas
plt.yticks([]) # remove eixo y
plt.title('Amount x Percent', fontsize=18)

plt.show()

How can I put the both Y axes values in the bars and line?

0

There are 0 answers