3
This commit is contained in:
24
q4/q4_1/q4_1.py
Normal file
24
q4/q4_1/q4_1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 设置中文字体(防止中文乱码)
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
with open('simulated-examination/q2_1_crawler/movies.json', 'r', encoding='utf-8') as f:
|
||||
movies = json.load(f)
|
||||
|
||||
genre_count = {}
|
||||
for m in movies:
|
||||
genre_count[m['genre']] = genre_count.get(m['genre'], 0) + 1
|
||||
|
||||
genres = list(genre_count.keys())
|
||||
counts = list(genre_count.values())
|
||||
|
||||
plt.figure()
|
||||
plt.bar(genres, counts)
|
||||
plt.title("类型电影数量分布")
|
||||
plt.xlabel("类型名称")
|
||||
plt.ylabel("电影数量")
|
||||
plt.savefig('q4_1_bar.png', dpi=150)
|
||||
# plt.show() # 如果是在IDE里不想显示弹窗可以注释掉
|
||||
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: 26 KiB |
18
q4/q4_2/q4_2.py
Normal file
18
q4/q4_2/q4_2.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
with open('simulated-examination/q2_1_crawler/movies.json', 'r', encoding='utf-8') as f:
|
||||
movies = json.load(f)
|
||||
|
||||
durations = [m['duration'] for m in movies]
|
||||
ratings = [m['rating'] for m in movies]
|
||||
|
||||
plt.figure()
|
||||
plt.scatter(durations, ratings, c='red', alpha=0.6)
|
||||
plt.title("时长与评分关系散点图")
|
||||
plt.xlabel("时长(分钟)")
|
||||
plt.ylabel("评分")
|
||||
plt.savefig('q4_2_scatter.png', dpi=150)
|
||||
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: 26 KiB |
16
q4/q4_3a/q4_3a.py
Normal file
16
q4/q4_3a/q4_3a.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
with open('simulated-examination/q2_1_crawler/movies.json', 'r', encoding='utf-8') as f:
|
||||
movies = json.load(f)
|
||||
|
||||
ratings = [m['rating'] for m in movies]
|
||||
|
||||
plt.figure()
|
||||
plt.hist(ratings, bins=5, color='blue')
|
||||
plt.title("评分分布")
|
||||
plt.xlabel("评分")
|
||||
plt.savefig('q4_3a_hist.png', dpi=150)
|
||||
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: 16 KiB |
16
q4/q4_3b/q4_3b.py
Normal file
16
q4/q4_3b/q4_3b.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
|
||||
with open('simulated-examination/q2_1_crawler/movies.json', 'r', encoding='utf-8') as f:
|
||||
movies = json.load(f)
|
||||
|
||||
durations = [m['duration'] for m in movies]
|
||||
|
||||
plt.figure()
|
||||
plt.hist(durations, bins=5, color='green')
|
||||
plt.title("时长分布")
|
||||
plt.xlabel("时长(分钟)")
|
||||
plt.savefig('q4_3b_hist.png', dpi=150)
|
||||
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: 19 KiB |
Reference in New Issue
Block a user