21 lines
435 B
Python
21 lines
435 B
Python
# 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("✅ 时长直方图生成成功!") |