From 511a86fb27fbbbfeed977b584a3f07b97e248acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E8=89=BA=E6=AC=A3?= <2509165020@student.example.com> Date: Tue, 23 Jun 2026 11:26:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- q4_1.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 q4_1.py diff --git a/q4_1.py b/q4_1.py new file mode 100644 index 0000000..853ab26 --- /dev/null +++ b/q4_1.py @@ -0,0 +1,24 @@ +import json +import matplotlib.pyplot as plt + +with open("movies.json", "r", encoding="utf-8") as f: + data = json.load(f) +movies = data["movies"] + +genre_count = {} +for movie in movies: + genre = movie["genre"] + if genre in genre_count: + genre_count[genre] += 1 + else: + genre_count[genre] = 1 +genres = list(genre_count.keys()) +counts = list(genre_count.values()) +plt.figure(figsize=(8, 5)) +plt.bar(genres, counts) +plt.xlabel("类型名称") +plt.ylabel("电影数量") +plt.title("类型电影数量分布") +plt.savefig("q4_1_bar.png", dpi=150, bbox_inches="tight") + +plt.show() \ No newline at end of file