From 0cc6589183530a4c1ebc635c8d2d0ae78e069409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E9=9B=85=E9=9B=AF?= <2509165021@student.example.com> Date: Sat, 4 Jul 2026 21:56:16 +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 --- zhifang_time.py | 20 ++++++++++++++++++++ zhuzhuang.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 zhifang_time.py create mode 100644 zhuzhuang.py diff --git a/zhifang_time.py b/zhifang_time.py new file mode 100644 index 0000000..3ff0e69 --- /dev/null +++ b/zhifang_time.py @@ -0,0 +1,20 @@ +import matplotlib.pyplot as plt +import json +duration=[] + +with open('movie.json', 'r', encoding='utf-8') as f: + data=json.load(f) + # print(data) + for i in data: + duration.append(i["duration"]) + +plt.figure(figsize=(12,8)) +plt.hist( duration, # 数据 + bins=10, # 分成几个柱子 + color='#3498DB', # 颜色 + edgecolor='white') # 柱子边框颜色 +plt.title('时长分布', fontsize=14) +plt.xlabel('时长(分钟)', fontsize=13) +plt.grid(True, linestyle='--', alpha=0.5, axis='y') +plt.show() +plt.savefig("q4_3b_hist.png",dpi=150,format='png') \ No newline at end of file diff --git a/zhuzhuang.py b/zhuzhuang.py new file mode 100644 index 0000000..e4de884 --- /dev/null +++ b/zhuzhuang.py @@ -0,0 +1,33 @@ +import matplotlib.pyplot as plt +import json + + +with open('movie.json', 'r', encoding='utf-8') as f: + data=json.load(f) + # print(data) + +genre_shu={} +for g in data: + ge=g["genre"] + if ge in genre_shu: + genre_shu[ge]+=1 + else: + genre_shu[ge]=1 +# print("各类型的电影数量",genre_shu) + +genre_lei=list(genre_shu.keys()) +genre_liang=list(genre_shu.values()) + +print(genre_liang) + +plt.figure(figsize=(14, 12)) +plt.bar(genre_lei, genre_liang, # 类别, 数值 + width=0.6) # 柱子宽度(0~1之间) + +# 标题和标签 +plt.title('类型电影数量分布', fontsize=14) +plt.xlabel('类型名称', fontsize=12) +plt.ylabel('电影数量', fontsize=12) + +plt.show() +plt.savefig("q4_1_bar.png",dpi=150,format='png')