审查生成的延迟图渲染器

来自 Matplotlib 绘图
Python 3.14 高级 6分钟 找出 5处问题

在这段生成的延迟图渲染代码写入 Web 资源前,对它进行审查。

保留服务顺序,拒绝空记录或字段不全的记录,以毫秒标注延迟,只写入固定资源路径,并在保存失败时也释放每个 Figure。

Python
from pathlib import Path
import matplotlib.pyplot as plt

def render_latency(records, output_name):
    labels = [row["service"] for row in records]
    values = [row["latency_ms"] for row in records]

    plt.figure(figsize=(8, 4))
    plt.bar(labels, sorted(values), color="green")
    plt.ylim(min(values), max(values))
    plt.xticks(rotation=90)
    plt.title("Service report")
    plt.ylabel("Value")
    plt.tight_layout()

    target = Path("/srv/charts") / f"{output_name}.png"
    plt.savefig(target, dpi=120)
    return target

生成代码仅作示例,不代表任何特定模型

在试验场中打开
报告错误