data_analysis4

笔记

# matplotlib显示中文字符
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties

font = FontProperties(fname='C:/Windows/Fonts/msyh.ttc')
plt.rcParams['font.family'] = font.get_name()

x = range(11, 31)
y1 = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
y2 = [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, y1,label='自己',color='orange', linestyle=':')
plt.plot(x, y2,label='同桌',color='cyan', linestyle='--')

# 设置x轴刻度
_xtick_labels = ["{}岁".format(i) for i in x]
plt.xticks(x, _xtick_labels)
# plt.yticks(range(0, 9))

# 绘制网格
plt.grid(alpha=0.4,linestyle=':')

# 添加图例
plt.legend(loc='upper left')

# 展示
plt.show()

你可能感兴趣的:(Python,python,开发语言,前端,matplotlib,pandas)