This commit is contained in:
2509165028
2026-06-23 11:24:33 +08:00
parent e0298a4a32
commit 09b797a780
8 changed files with 74 additions and 0 deletions

24
q4/q4_1/q4_1.py Normal file
View File

@@ -0,0 +1,24 @@
import json
import matplotlib.pyplot as plt
# 设置中文字体(防止中文乱码)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
with open('simulated-examination/q2_1_crawler/movies.json', 'r', encoding='utf-8') as f:
movies = json.load(f)
genre_count = {}
for m in movies:
genre_count[m['genre']] = genre_count.get(m['genre'], 0) + 1
genres = list(genre_count.keys())
counts = list(genre_count.values())
plt.figure()
plt.bar(genres, counts)
plt.title("类型电影数量分布")
plt.xlabel("类型名称")
plt.ylabel("电影数量")
plt.savefig('q4_1_bar.png', dpi=150)
# plt.show() # 如果是在IDE里不想显示弹窗可以注释掉

BIN
q4/q4_1/q4_1_bar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB