Files
2026-07-06 14:19:45 +08:00

25 lines
454 B
Python

# 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 完成!")