I want to draw a line & bar chart by matplotlib.my code is like this, you can see data label's format is number in my chart:
import matplotlib.pyplot as plt
from matplotlib import ticker
import numpy as np
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
plt.figure(figsize=(9, 6), dpi=100)
x = ['>12 Months','6-12 Months','3-6 Months','1-3 Months','1-4 Weeks','>1 Times Per Week']
y = [0.0964,0.1607,0.4158,0.3054,0.0215,0.0001]
z = [11544,19247,49794,36572,2578,16]
plt.bar(x=x, height=z, label='Vehicles Num', color='Blue', alpha=0.7, width=0.5)
plt.legend(loc="upper left")
plt.title("Frequency Distribution of Hood Ajar/Closed Events",size=15)
plt.xlabel("Frequency",size=13)
plt.ylabel("Number of Vehicles",size=13)
ax2 = plt.twinx()
ax2.set_ylabel("Percentage",size=13)
ax2.plot(y)
ax2.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=1, decimals=1))
plt.plot(x, y, "r", marker='.', c='r', ms=8, linewidth='1', label="Percentage")
plt.legend(loc="upper right")
for a, b in zip(x, y):
plt.text(a, b, b, ha='center',va='bottom',fontsize=13)
plt.show()
The result I want: the data label list "y", can show like:9.64%, 16.07%
Many Thanks~