添加 4-1

This commit is contained in:
2026-07-06 14:16:58 +08:00
parent 3023eb1179
commit 5bc6a4f3ea

25
4-1 Normal file
View File

@@ -0,0 +1,25 @@
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()