17 lines
406 B
Plaintext
17 lines
406 B
Plaintext
# q4/q4_3a/q4_3a.py
|
|
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"]
|
|
ratings = [m["rating"] for m in movies]
|
|
|
|
# 直方图 bins=5 蓝色
|
|
plt.hist(ratings, bins=5, color="blue")
|
|
plt.title("评分分布")
|
|
plt.xlabel("评分")
|
|
plt.tight_layout()
|
|
|
|
plt.savefig("q4_3a_hist.png", dpi=150)
|
|
plt.show() |