更新 q2_1_crawler/zhifang_rating.py
This commit is contained in:
@@ -1,21 +1,21 @@
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import json
|
import json
|
||||||
|
|
||||||
rating=[]
|
rating=[]
|
||||||
|
|
||||||
with open('movie.json', 'r', encoding='utf-8') as f:
|
with open('movie.json', 'r', encoding='utf-8') as f:
|
||||||
data=json.load(f)
|
data=json.load(f)
|
||||||
# print(data)
|
# print(data)
|
||||||
for i in data:
|
for i in data:
|
||||||
rating.append(i["rating"])
|
rating.append(i["rating"])
|
||||||
|
|
||||||
plt.figure(figsize=(12,8))
|
plt.figure(figsize=(12,8))
|
||||||
plt.hist(rating, # 数据
|
plt.hist(rating, # 数据
|
||||||
bins=10, # 分成几个柱子
|
bins=10, # 分成几个柱子
|
||||||
color='#3498DB', # 颜色
|
color='#3498DB', # 颜色
|
||||||
edgecolor='white') # 柱子边框颜色
|
edgecolor='white') # 柱子边框颜色
|
||||||
plt.title('评分分布', fontsize=14)
|
plt.title('评分分布', fontsize=14)
|
||||||
plt.xlabel('评分', fontsize=13)
|
plt.xlabel('评分', fontsize=13)
|
||||||
plt.grid(True, linestyle='--', alpha=0.5, axis='y')
|
plt.grid(True, linestyle='--', alpha=0.5, axis='y')
|
||||||
plt.show()
|
plt.savefig("q4_3a_hist.png",dpi=150,format='png')
|
||||||
plt.savefig("q4_3a_hist.png",dpi=150,format='png')
|
plt.show()
|
||||||
|
|||||||
Reference in New Issue
Block a user