From ea1103f040c0df65c6cff7b29fe4e325243cd63b 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:24:41 +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=5F3b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- q4/q4_3b/q4_3b.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 q4/q4_3b/q4_3b.py diff --git a/q4/q4_3b/q4_3b.py b/q4/q4_3b/q4_3b.py new file mode 100644 index 0000000..948a7be --- /dev/null +++ b/q4/q4_3b/q4_3b.py @@ -0,0 +1,35 @@ +# 全部导入放最上方 +import matplotlib.pyplot as plt +import json +import os + +duration = [] + +# 读取json文件 +with open(r'C:\Users\34481\OneDrive\Desktop\作业\新建文件夹\simulated-examination\q4\q4_3b\movies.json', 'r', encoding='utf-8') as f: + data = json.load(f) + +# 提取时长数据 +for i in data: + duration.append(i["duration"]) + +# 创建画布 +plt.figure(figsize=(12, 8)) + +# 修正hist参数分行语法,绘图参数完全不变,图形一致 +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') + +# 保存图片逻辑不变 +save_path = os.path.join(os.path.dirname(__file__), "q4_3b_hist.png") +plt.savefig(save_path, dpi=150, format='png') +plt.show() \ No newline at end of file