完成 q4_3 评分+时长直方图
This commit is contained in:
25
q4/q4_3a/q4_3a.py
Normal file
25
q4/q4_3a/q4_3a.py
Normal 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 完成!")
|
||||
Reference in New Issue
Block a user