Files
2509165008 96d521be98 完成
2026-06-25 15:54:43 +08:00

34 lines
727 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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