上传文件至 /

This commit is contained in:
2026-06-23 11:26:52 +08:00
parent 9478b8c0cc
commit 511a86fb27

24
q4_1.py Normal file
View File

@@ -0,0 +1,24 @@
import json
import matplotlib.pyplot as plt
with open("movies.json", "r", encoding="utf-8") as f:
data = json.load(f)
movies = data["movies"]
genre_count = {}
for movie in movies:
genre = movie["genre"]
if genre in genre_count:
genre_count[genre] += 1
else:
genre_count[genre] = 1
genres = list(genre_count.keys())
counts = list(genre_count.values())
plt.figure(figsize=(8, 5))
plt.bar(genres, counts)
plt.xlabel("类型名称")
plt.ylabel("电影数量")
plt.title("类型电影数量分布")
plt.savefig("q4_1_bar.png", dpi=150, bbox_inches="tight")
plt.show()