From 0462c20ce2ca701184e2c71ccad85c0956d4bc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BC=9F=E6=B3=B0?= <2509165006@student.example.com> Date: Mon, 6 Jul 2026 14:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20q4/q4=5F1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- q4/q4_1/q4_1.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 q4/q4_1/q4_1.py diff --git a/q4/q4_1/q4_1.py b/q4/q4_1/q4_1.py new file mode 100644 index 0000000..20e1b1f --- /dev/null +++ b/q4/q4_1/q4_1.py @@ -0,0 +1,21 @@ +import json +import matplotlib.pyplot as plt + +movies = json.load(open('../movies.json', encoding='utf-8'))['movies'] +# print(movies) + +genres = {} +for m in movies: + g = m['genre'] + if g in genres: + genres[g] = genres[g] + 1 + else: + genres[g] = 1 + +print(genres) +plt.figure(figsize=(8,5)) +plt.bar(genres.keys(), genres.values()) +plt.title('类型电影数量分布') +plt.xlabel('类型') +plt.ylabel('数量') +plt.savefig('q4_1_bar.png', dpi=150) \ No newline at end of file