'''
折线图:plt.plot(x,y)
题目:你和同桌从11岁到30岁每年交的女(男)朋友的数量如列表a和b,请在一个图中绘制出该数据的折线图,以便比较自己和同桌20年间的差异,同时分析每年交女(男)朋友的数量趋势
a = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
b = [1, 0, 3, 1, 2, 2, 3, 3, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]
要求:
Y轴表示个数
X轴表示岁数,比如11岁,12岁
'''
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname='C:\\Windows\\Fonts\\FZSTK.TTF')
x = range(11,31)
y_1 = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
y_2 = [1, 0, 3, 1, 2, 2, 3, 3, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y_1,label='自己',color='r',linestyle=':')
plt.plot(x,y_2,label='同桌',color='cyan',linestyle='--')
_x = x
_xtick_labels= ['{}岁'.format(i) for i in range(11,31)]
plt.xticks(_x,_xtick_labels,fontproperties=my_font)
# plt.yctick(range(0,9))
plt.grid(alpha=0.4,linestyle=':')
plt.legend(prop=my_font,loc='upper right')
plt.show()
1---折线图(matplotlib)
最新推荐文章于 2023-06-21 20:33:15 发布