This commit is contained in:
2509165008
2026-06-25 15:54:43 +08:00
parent b91c3c9f4f
commit 96d521be98
30 changed files with 428 additions and 737 deletions

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

@@ -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()