32 lines
757 B
Python
32 lines
757 B
Python
import matplotlib
|
|
|
|
matplotlib.use("Agg")
|
|
|
|
import matplotlib.pyplot as plt
|
|
from matplotlib import font_manager
|
|
import config
|
|
import logging
|
|
|
|
logging.getLogger("matplotlib").setLevel(logging.WARNING)
|
|
|
|
# 从字体文件创建字体对象
|
|
FONT = font_manager.FontProperties(fname=config.FONT_PATH)
|
|
|
|
# 负号修复
|
|
plt.rcParams["axes.unicode_minus"] = False
|
|
|
|
|
|
def plot_line(times, values, title, ylabel, out_path):
|
|
plt.figure(figsize=(8, 4))
|
|
plt.plot(times, values, marker="o")
|
|
|
|
plt.title(title, fontproperties=FONT)
|
|
plt.xlabel("时间", fontproperties=FONT)
|
|
plt.ylabel(ylabel, fontproperties=FONT)
|
|
|
|
plt.xticks(rotation=45, fontproperties=FONT)
|
|
plt.grid(True)
|
|
plt.tight_layout()
|
|
plt.savefig(out_path, dpi=150)
|
|
plt.close()
|