diff --git a/q4/q4_3b/movies.json b/q4/q4_3b/movies.json new file mode 100644 index 0000000..32b16f9 --- /dev/null +++ b/q4/q4_3b/movies.json @@ -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 + } + ] +} diff --git a/q4/q4_3b/q4_3b.py b/q4/q4_3b/q4_3b.py new file mode 100644 index 0000000..124902a --- /dev/null +++ b/q4/q4_3b/q4_3b.py @@ -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("✅ 时长直方图生成成功!") \ No newline at end of file diff --git a/q4/q4_3b/q4_3b_hist.png b/q4/q4_3b/q4_3b_hist.png new file mode 100644 index 0000000..2db26b9 Binary files /dev/null and b/q4/q4_3b/q4_3b_hist.png differ