40 lines
916 B
Python
40 lines
916 B
Python
import matplotlib.pyplot as plt
|
|
import json
|
|
|
|
|
|
with open(r'D:\桌面\期末考试\simulated-examination\q2_1_crawler\movie.json', 'r', encoding='utf-8') as f:
|
|
data=json.load(f)
|
|
# print(data)
|
|
|
|
genre_shu={}
|
|
for g in data:
|
|
ge=g["genre"]
|
|
if ge in genre_shu:
|
|
genre_shu[ge]+=1
|
|
else:
|
|
genre_shu[ge]=1
|
|
# print("各类型的电影数量",genre_shu)
|
|
|
|
genre_lei=list(genre_shu.keys())
|
|
genre_liang=list(genre_shu.values())
|
|
|
|
print(genre_liang)
|
|
|
|
plt.figure(figsize=(14, 12))
|
|
plt.bar(genre_lei, genre_liang,
|
|
width=0.6)
|
|
|
|
# 标题和标签
|
|
plt.title('类型电影数量分布', fontsize=14)
|
|
plt.xlabel('类型名称', fontsize=12)
|
|
plt.ylabel('电影数量', fontsize=12)
|
|
|
|
|
|
import os
|
|
save_path = os.path.join(os.path.dirname(__file__),"q4_1_bar.png")
|
|
plt.savefig(save_path, dpi=150,format='png')
|
|
plt.show()
|
|
|
|
|
|
|
|
#with open('movie.json', 'r', encoding='utf-8') as f: |