28 lines
857 B
Python
28 lines
857 B
Python
import matplotlib.pyplot as plt
|
|
import json
|
|
|
|
rating=[]
|
|
duration=[]
|
|
|
|
with open(r'D:\桌面\期末考试\simulated-examination\q2_1_crawler\movie.json', 'r', encoding='utf-8') as f:
|
|
data=json.load(f)
|
|
# print(data)
|
|
for i in data:
|
|
rating.append(i["rating"])
|
|
duration.append(i["duration"])
|
|
plt.figure(figsize=(12, 8))
|
|
plt.scatter(duration, rating,
|
|
c='red',
|
|
s=80, # 点的大小
|
|
alpha=0.6, # 透明度
|
|
edgecolors='white') # 点的边框
|
|
plt.title('时长与评分关系散点图', fontsize=14)
|
|
plt.xlabel('时长', fontsize=12)
|
|
plt.ylabel('评分', fontsize=12)
|
|
plt.grid(True, linestyle='--', alpha=0.5)
|
|
|
|
|
|
import os
|
|
save_path = os.path.join(os.path.dirname(__file__),"q4_2_scatter.png")
|
|
plt.savefig(save_path, dpi=150,format='png')
|
|
plt.show() |