期末
This commit is contained in:
102
q4/movies.json
Normal file
102
q4/movies.json
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"title": "泰坦尼克号",
|
||||||
|
"director": "Frank Darabont",
|
||||||
|
"year": 1994,
|
||||||
|
"rating": 9.1,
|
||||||
|
"duration": 150,
|
||||||
|
"genre": "剧情",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"title": "肖申克的救赎",
|
||||||
|
"director": "陈凯歌",
|
||||||
|
"year": 2004,
|
||||||
|
"rating": 7.8,
|
||||||
|
"duration": 180,
|
||||||
|
"genre": "剧情",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"title": "霸王别姬",
|
||||||
|
"director": "Robert Zemeckis",
|
||||||
|
"year": 2014,
|
||||||
|
"rating": 7.6,
|
||||||
|
"duration": 160,
|
||||||
|
"genre": "冒险",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"title": "忠犬八公的故事",
|
||||||
|
"director": "James Cameron",
|
||||||
|
"year": 1992,
|
||||||
|
"rating": 9.5,
|
||||||
|
"duration": 167,
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"title": "盗梦空间",
|
||||||
|
"director": "宫崎骏",
|
||||||
|
"year": 2014,
|
||||||
|
"rating": 8.2,
|
||||||
|
"duration": 176,
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"title": "阿甘正传",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": 2016,
|
||||||
|
"rating": 6.9,
|
||||||
|
"duration": 97,
|
||||||
|
"genre": "动画",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"title": "三傻大闹宝莱坞",
|
||||||
|
"director": "Lasse Hallström",
|
||||||
|
"year": 2003,
|
||||||
|
"rating": 7.0,
|
||||||
|
"duration": 122,
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"title": "放牛班的春天",
|
||||||
|
"director": "Rajkumar Hirani",
|
||||||
|
"year": 2021,
|
||||||
|
"rating": 8.7,
|
||||||
|
"duration": 140,
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"title": "星际穿越",
|
||||||
|
"director": "Christophe Barratier",
|
||||||
|
"year": 2002,
|
||||||
|
"rating": 9.0,
|
||||||
|
"duration": 125,
|
||||||
|
"genre": "冒险",
|
||||||
|
"actors_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"title": "千与千寻",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": 2021,
|
||||||
|
"rating": 7.3,
|
||||||
|
"duration": 173,
|
||||||
|
"genre": "剧情",
|
||||||
|
"actors_count": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
102
q4/q4_1/movies.json
Normal file
102
q4/q4_1/movies.json
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"title": "泰坦尼克号",
|
||||||
|
"director": "Frank Darabont",
|
||||||
|
"year": 1994,
|
||||||
|
"rating": 9.1,
|
||||||
|
"duration": 150,
|
||||||
|
"genre": "剧情",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"title": "肖申克的救赎",
|
||||||
|
"director": "陈凯歌",
|
||||||
|
"year": 2004,
|
||||||
|
"rating": 7.8,
|
||||||
|
"duration": 180,
|
||||||
|
"genre": "剧情",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"title": "霸王别姬",
|
||||||
|
"director": "Robert Zemeckis",
|
||||||
|
"year": 2014,
|
||||||
|
"rating": 7.6,
|
||||||
|
"duration": 160,
|
||||||
|
"genre": "冒险",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"title": "忠犬八公的故事",
|
||||||
|
"director": "James Cameron",
|
||||||
|
"year": 1992,
|
||||||
|
"rating": 9.5,
|
||||||
|
"duration": 167,
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"title": "盗梦空间",
|
||||||
|
"director": "宫崎骏",
|
||||||
|
"year": 2014,
|
||||||
|
"rating": 8.2,
|
||||||
|
"duration": 176,
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"title": "阿甘正传",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": 2016,
|
||||||
|
"rating": 6.9,
|
||||||
|
"duration": 97,
|
||||||
|
"genre": "动画",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"title": "三傻大闹宝莱坞",
|
||||||
|
"director": "Lasse Hallström",
|
||||||
|
"year": 2003,
|
||||||
|
"rating": 7.0,
|
||||||
|
"duration": 122,
|
||||||
|
"genre": "悬疑",
|
||||||
|
"actors_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"title": "放牛班的春天",
|
||||||
|
"director": "Rajkumar Hirani",
|
||||||
|
"year": 2021,
|
||||||
|
"rating": 8.7,
|
||||||
|
"duration": 140,
|
||||||
|
"genre": "喜剧",
|
||||||
|
"actors_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"title": "星际穿越",
|
||||||
|
"director": "Christophe Barratier",
|
||||||
|
"year": 2002,
|
||||||
|
"rating": 9.0,
|
||||||
|
"duration": 125,
|
||||||
|
"genre": "冒险",
|
||||||
|
"actors_count": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"title": "千与千寻",
|
||||||
|
"director": "Christopher Nolan",
|
||||||
|
"year": 2021,
|
||||||
|
"rating": 7.3,
|
||||||
|
"duration": 173,
|
||||||
|
"genre": "剧情",
|
||||||
|
"actors_count": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,6 +1,16 @@
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import json
|
import json
|
||||||
with open ("movies.json","r",encoding='utf-8') as f:
|
movies= json.load(open('movies.json',encoding='utf-8'))
|
||||||
print(f)
|
genres= {}
|
||||||
genre_count=()
|
for m in movies:
|
||||||
plt.bar
|
g=m['genre']
|
||||||
|
if g in genres:
|
||||||
|
genres['g'] = genres['g']+1
|
||||||
|
else:
|
||||||
|
genres['g']=1
|
||||||
|
plt.figure(figsize=(8,5))
|
||||||
|
plt.bar(genres.keys(),genres.values())
|
||||||
|
plt.title("类型电影数量分布")
|
||||||
|
plt.xlabel("类型")
|
||||||
|
plt.ylabel("数量")
|
||||||
|
plt.savefig('q4_1_bar.png', dpi=150)
|
||||||
|
|||||||
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: 12 KiB |
15
q4/q4_2/q4_2.py
Normal file
15
q4/q4_2/q4_2.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
movies= json.load(open('movies.json',encoding='utf-8'))
|
||||||
|
rating=[]
|
||||||
|
durations=[]
|
||||||
|
for m in movies:
|
||||||
|
rating.append(m['rating'])
|
||||||
|
durations.append(m['duration'])
|
||||||
|
|
||||||
|
plt.figure(figsize=(8,5))
|
||||||
|
plt.scatter(durations,rating,color='red',alpha=0.6)
|
||||||
|
plt.title("时长与评分关系散点图")
|
||||||
|
plt.xlabel('duration')
|
||||||
|
plt.ylabel('rating')
|
||||||
|
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: 22 KiB |
14
q4/q4_3a/q4-3a.py
Normal file
14
q4/q4_3a/q4-3a.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
movies= json.load(open('movies.json',encoding='utf-8'))
|
||||||
|
rating=[]
|
||||||
|
durations=[]
|
||||||
|
for m in movies:
|
||||||
|
rating.append(m['rating'])
|
||||||
|
durations.append(m['duration'])
|
||||||
|
plt.title("评分分布")
|
||||||
|
plt.xlabel("评分")
|
||||||
|
plt.figure(figsize=(8,5))
|
||||||
|
plt.hist(rating,bins=5,color='blue')
|
||||||
|
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: 14 KiB |
13
q4/q4_3b/q4_3b.py
Normal file
13
q4/q4_3b/q4_3b.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import json
|
||||||
|
movies= json.load(open('movies.json',encoding='utf-8'))
|
||||||
|
rating=[]
|
||||||
|
durations=[]
|
||||||
|
for m in movies:
|
||||||
|
durations.append(m['duration'])
|
||||||
|
plt.title("时长分布")
|
||||||
|
plt.xlabel("min")
|
||||||
|
plt.figure(figsize=(8,5))
|
||||||
|
plt.hist(durations,bins=5,color='green')
|
||||||
|
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: 16 KiB |
Reference in New Issue
Block a user