Matplotlib
·
77
个字
·
1
分钟 读完
# coding=utf-8
from matplotlib import pyplot as plt
import random
# 显示中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
x = range(0, 10)
y1 = [random.randint(0, 10) for i in range(10)]
y2 = [random.randint(0, 10) for i in range(10)]
plt.figure(figsize=(20, 8), dpi=80)
plt.plot(x, y1, label="小明", color="red", linestyle="--", linewidth=3, alpha=0.2)
plt.plot(x, y2, label="小红", color="orange", linestyle=":", linewidth=3)
plt.grid(alpha=0.4)
plt.legend()
_x = list(x)
_xtick_labels = ["中文".format(i) for i in range(10)]
plt.xticks(_x[::2], _xtick_labels[::2], rotation=70)
plt.xlabel("时间")
plt.ylabel("刻度")
plt.title("折线图")
plt.show()