From ffbe5b339a094b63082a48a406396a3923cbc5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E5=AE=87=E6=B6=B5?= <2509165016@student.example.com> Date: Sun, 5 Jul 2026 18:38:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E6=97=B6=E9=95=BF?= =?UTF-8?q?=E7=9B=B4=E6=96=B9=E5=9B=BEq4=5F3b.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 时长直方图q4_3b.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 时长直方图q4_3b.py diff --git a/时长直方图q4_3b.py b/时长直方图q4_3b.py new file mode 100644 index 0000000..f27de84 --- /dev/null +++ b/时长直方图q4_3b.py @@ -0,0 +1,17 @@ +# q4/q4_3b/q4_3b.py +import json +import matplotlib.pyplot as plt + +with open("../q2_1_crawler/movies.json", "r", encoding="utf-8") as f: + data = json.load(f) +movies = data["movies"] +durations = [m["duration"] for m in movies] + +# 直方图 bins=5 绿色 +plt.hist(durations, bins=5, color="green") +plt.title("时长分布") +plt.xlabel("时长(分钟)") +plt.tight_layout() + +plt.savefig("q4_3b_hist.png", dpi=150) +plt.show() \ No newline at end of file