python中折线图的数据标签

时间:2018-06-27 14:38:32

标签: python matplotlib linechart labels

我想在下面的编码中添加数据标签,请有人帮帮我! this is my output,我想要这样的输出图像... this is what i want like labels over the points

from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure(figsize=(8, 4))
year=[1955,1960,1965,1970,1975,1980,1985,1990,1995,2000,2005,2010,2015,2016,2017,2018]
ind=[1.69,1.89,2.06,2.15,2.34,2.32,2.33,2.17,2.00,1.86,1.67,1.47,1.24,1.15,1.13,1.11]
china=[1.96,1.49,1.90,2.68,2.23,1.54,1.50,1.83,1.13,0.69,0.59,0.57,0.54,0.46,0.43,0.39]
plt.plot(ind,color='red',label='India',marker='o', markerfacecolor='red', markersize=6)
plt.plot(china,color='blue',label='China',marker='o', markerfacecolor='blue', markersize=6,)
plt.grid()
plt.legend(loc="best")
plt.xticks(np.arange(len(year)),year,rotation=90)
plt.title("Population Comparison")
plt.xlabel('Years')
plt.ylabel('Rate of Increase in Population(%)')
plt.show()

0 个答案:

没有答案