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,2,3,1,1,1,1,1,2,1,1,2,3,2,2]
要求:
from matplotlib import pyplot as plt
import matplotlib # 设置全局字体 ,支持ttf,不支持ttc
font = {
‘family’:‘SimHei’,
‘weight’:‘bold’,
‘size’:12
}
matplotlib.rc(“font”, **font)
x = list(range(11,31,1))
y_a =[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y_b =[1,0,3,1,2,2,2,3,1,1,1,1,1,2,1,1,2,3,2,2]
plt.figure(figsize=(12,8))
plt.plot(x,y_a,marker="*",label=“a”,color=‘r’ ) # 绘制图形
plt.plot(x,y_b,marker=“o”,color=‘b’)
plt.xticks(x)
x_t = [i for i in range(11,31)]
x_l = [f"{i}岁" for i in range(11,31)]
plt.xticks(x_t,x_l,rotation=0)
plt.yticks(range(min(y_b),max(y_a)+1))
plt.xlabel(“年龄”)
plt.ylabel(“交往朋友的数量”)
plt.title(“调查报告”)
plt.grid()
plt.savefig(“朋友.jpg”)