完成 q4_3 评分+时长直方图
This commit is contained in:
21
q4/q4_3b/q4_3b.py
Normal file
21
q4/q4_3b/q4_3b.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# q4_3b.py
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
with open("../q4_2/movies.json", "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
movies = data["movies"]
|
||||
|
||||
durations = []
|
||||
for m in movies:
|
||||
durations.append(m["duration"])
|
||||
|
||||
plt.hist(durations, bins=5, color="green")
|
||||
plt.title("时长分布")
|
||||
plt.xlabel("时长(分钟)")
|
||||
|
||||
plt.savefig("q4_3b_hist.png", dpi=150)
|
||||
plt.close()
|
||||
|
||||
print("✅ 时长直方图生成成功!")
|
||||
Reference in New Issue
Block a user