From 63d3879a6ebd269e4d11672aef28cdb18dc61d33 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:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=20=E8=AF=84=E5=88=86=20vs?= =?UTF-8?q?=20=E6=97=B6=E9=95=BF=E6=95=A3=E7=82=B9=E5=9B=BEq4-2.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 评分 vs 时长散点图q4-2.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 评分 vs 时长散点图q4-2.py diff --git a/ 评分 vs 时长散点图q4-2.py b/ 评分 vs 时长散点图q4-2.py new file mode 100644 index 0000000..9751833 --- /dev/null +++ b/ 评分 vs 时长散点图q4-2.py @@ -0,0 +1,22 @@ +# q4/q4_2/q4_2.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"] + +# 提取x时长、y评分 +duration = [m["duration"] for m in movies] +rating = [m["rating"] for m in movies] + +# 散点图:红色,透明度0.6 +plt.scatter(duration, rating, color="red", alpha=0.6) +plt.title("时长与评分关系散点图") +plt.xlabel("时长(分钟)") +plt.ylabel("评分") +plt.tight_layout() + +plt.savefig("q4_2_scatter.png", dpi=150) +plt.show() \ No newline at end of file