上传文件至 q4/q4_1

This commit is contained in:
2026-06-23 11:13:42 +08:00
parent ede35f6a8e
commit 5d5283d8e0

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

@@ -0,0 +1,19 @@
import json
import matplotlib.pyplot as plt
with open("../q2_1_crawler/movies.json","r",encoding="utf-8") as f:
data = json.load(f)
movies = data["movies"]
genre_cnt = {}
for m in movies:
g = m["genre"]
genre_cnt[g] = genre_cnt.get(g,0)+1
x = list(genre_cnt.keys())
y = list(genre_cnt.values())
plt.bar(x,y)
plt.tight_layout()
plt.savefig("q4_1_bar.png",dpi=150)
plt.close()