From 854b7044c62d03e4645c9680a99de7168ba6a205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=96=87=E7=90=B3?= <2509165042@student.example.com> Date: Thu, 25 Jun 2026 16:29:03 +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 --- 1.py | 19 +++++++++++++++++++ 2.py | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 1.py create mode 100644 2.py diff --git a/1.py b/1.py new file mode 100644 index 0000000..dffbf6f --- /dev/null +++ b/1.py @@ -0,0 +1,19 @@ +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 diff --git a/2.py b/2.py new file mode 100644 index 0000000..360c462 --- /dev/null +++ b/2.py @@ -0,0 +1,17 @@ +import json +import matplotlib.pyplot as plt + +movies = json.load(open('movies.json', encoding='utf-8'))['movies'] +# print(movies) +ratings = [] +durations = [] +for m in movies: + ratings.append(m['rating']) + durations.append(m['duration']) + +plt.figure(figsize=(8,5)) +plt.scatter(durations,ratings,color='red',alpha=0.6) +plt.title('时长与评分关系散点图') +plt.xlabel('duration') +plt.ylabel('rating') +plt.savefig('q4_2_scatter.png', dpi=150) \ No newline at end of file