完成 q4_3 评分+时长直方图

This commit is contained in:
2509165005
2026-07-06 14:19:45 +08:00
parent d107481792
commit 1dd52409e7
3 changed files with 130 additions and 0 deletions

105
q4/q4_3a/movies.json Normal file
View 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
}
]
}

25
q4/q4_3a/q4_3a.py Normal file
View 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 完成!")

BIN
q4/q4_3a/q4_3a_hist.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB