完成 q4_3 评分+时长直方图
This commit is contained in:
105
q4/q4_3b/movies.json
Normal file
105
q4/q4_3b/movies.json
Normal file
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"data_code": "B-20260705-9162",
|
||||
"movies": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "放牛班的春天",
|
||||
"director": "Frank Darabont",
|
||||
"year": 2007,
|
||||
"rating": 8.9,
|
||||
"duration": 155,
|
||||
"genre": "悬疑",
|
||||
"actors_count": 5
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "霸王别姬",
|
||||
"director": "陈凯歌",
|
||||
"year": 2018,
|
||||
"rating": 6.6,
|
||||
"duration": 143,
|
||||
"genre": "剧情",
|
||||
"actors_count": 4
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "星际穿越",
|
||||
"director": "Robert Zemeckis",
|
||||
"year": 2018,
|
||||
"rating": 8.4,
|
||||
"duration": 165,
|
||||
"genre": "悬疑",
|
||||
"actors_count": 5
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "肖申克的救赎",
|
||||
"director": "James Cameron",
|
||||
"year": 2008,
|
||||
"rating": 8.6,
|
||||
"duration": 124,
|
||||
"genre": "剧情",
|
||||
"actors_count": 5
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "盗梦空间",
|
||||
"director": "宫崎骏",
|
||||
"year": 1993,
|
||||
"rating": 7.8,
|
||||
"duration": 90,
|
||||
"genre": "爱情",
|
||||
"actors_count": 2
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "泰坦尼克号",
|
||||
"director": "Christopher Nolan",
|
||||
"year": 2001,
|
||||
"rating": 6.7,
|
||||
"duration": 175,
|
||||
"genre": "喜剧",
|
||||
"actors_count": 4
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "忠犬八公的故事",
|
||||
"director": "Lasse Hallström",
|
||||
"year": 2004,
|
||||
"rating": 8.2,
|
||||
"duration": 91,
|
||||
"genre": "动画",
|
||||
"actors_count": 3
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "三傻大闹宝莱坞",
|
||||
"director": "Rajkumar Hirani",
|
||||
"year": 2011,
|
||||
"rating": 6.3,
|
||||
"duration": 175,
|
||||
"genre": "冒险",
|
||||
"actors_count": 3
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "阿甘正传",
|
||||
"director": "Christophe Barratier",
|
||||
"year": 2022,
|
||||
"rating": 7.9,
|
||||
"duration": 107,
|
||||
"genre": "动画",
|
||||
"actors_count": 4
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"title": "千与千寻",
|
||||
"director": "Christopher Nolan",
|
||||
"year": 1993,
|
||||
"rating": 7.2,
|
||||
"duration": 129,
|
||||
"genre": "悬疑",
|
||||
"actors_count": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
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("✅ 时长直方图生成成功!")
|
||||
BIN
q4/q4_3b/q4_3b_hist.png
Normal file
BIN
q4/q4_3b/q4_3b_hist.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Reference in New Issue
Block a user