完成 q4_3 评分+时长直方图

This commit is contained in:
2509165005
2026-07-06 14:19:45 +08:00
parent d107481792
commit 1dd52409e7
3 changed files with 130 additions and 0 deletions

25
q4/q4_3a/q4_3a.py Normal file
View File

@@ -0,0 +1,25 @@
# q4_3a.py
import json
import matplotlib.pyplot as plt
# 读取数据
with open("movies.json", "r", encoding="utf-8") as f:
data = json.load(f)
movies = data["movies"]
# 提取评分
ratings = []
for m in movies:
ratings.append(m["rating"])
# 绘制直方图
plt.hist(ratings, bins=5, color="blue")
plt.title("评分分布")
plt.xlabel("评分")
# 保存图片
plt.savefig("q4_3a_hist.png", dpi=150)
plt.close()
print("✅ q4_3a 完成!")