Files
simulated-examination/q4/q4_1/q4_1.py
2509165045 d0658b1f49 期末
2026-06-25 17:42:13 +08:00

17 lines
414 B
Python

import matplotlib.pyplot as plt
import json
movies= json.load(open('movies.json',encoding='utf-8'))
genres= {}
for m in movies:
g=m['genre']
if g in genres:
genres['g'] = genres['g']+1
else:
genres['g']=1
plt.figure(figsize=(8,5))
plt.bar(genres.keys(),genres.values())
plt.title("类型电影数量分布")
plt.xlabel("类型")
plt.ylabel("数量")
plt.savefig('q4_1_bar.png', dpi=150)