上传文件至 q4/q4_1
This commit is contained in:
19
q4/q4_1/q4_1.py
Normal file
19
q4/q4_1/q4_1.py
Normal 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()
|
||||
Reference in New Issue
Block a user