完成期末练习
This commit is contained in:
40
q4/q4_1/q4_1.py
Normal file
40
q4/q4_1/q4_1.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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:
|
||||
BIN
q4/q4_1/q4_1_bar.png
Normal file
BIN
q4/q4_1/q4_1_bar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
28
q4/q4_2/q4_2.py
Normal file
28
q4/q4_2/q4_2.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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()
|
||||
BIN
q4/q4_2/q4_2_scatter.png
Normal file
BIN
q4/q4_2/q4_2_scatter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
24
q4/q4_3a/q4_3a.py
Normal file
24
q4/q4_3a/q4_3a.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import json
|
||||
|
||||
rating=[]
|
||||
|
||||
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"])
|
||||
|
||||
plt.figure(figsize=(12,8))
|
||||
plt.hist(rating, # 数据
|
||||
bins=10, # 分成几个柱子
|
||||
color='#3498DB', # 颜色
|
||||
edgecolor='white') # 柱子边框颜色
|
||||
plt.title('评分分布', fontsize=14)
|
||||
plt.xlabel('评分', fontsize=13)
|
||||
plt.grid(True, linestyle='--', alpha=0.5, axis='y')
|
||||
|
||||
import os
|
||||
save_path = os.path.join(os.path.dirname(__file__),"q4_3a_hist.png")
|
||||
plt.savefig(save_path, dpi=150,format='png')
|
||||
plt.show()
|
||||
BIN
q4/q4_3a/q4_3a_hist.png
Normal file
BIN
q4/q4_3a/q4_3a_hist.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
24
q4/q4_3b/q4_3b.py
Normal file
24
q4/q4_3b/q4_3b.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import json
|
||||
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:
|
||||
duration.append(i["duration"])
|
||||
|
||||
plt.figure(figsize=(12,8))
|
||||
plt.hist( duration, # 数据
|
||||
bins=10, # 分成几个柱子
|
||||
color='#3498DB', # 颜色
|
||||
edgecolor='white') # 柱子边框颜色
|
||||
plt.title('时长分布', fontsize=14)
|
||||
plt.xlabel('时长(分钟)', fontsize=13)
|
||||
plt.grid(True, linestyle='--', alpha=0.5, axis='y')
|
||||
|
||||
|
||||
import os
|
||||
save_path = os.path.join(os.path.dirname(__file__),"q4_3b_hist.png")
|
||||
plt.savefig(save_path, dpi=150,format='png')
|
||||
plt.show()
|
||||
BIN
q4/q4_3b/q4_3b_hist.png
Normal file
BIN
q4/q4_3b/q4_3b_hist.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Reference in New Issue
Block a user