diff --git a/q4/movies.json b/q4/movies.json new file mode 100644 index 0000000..aca6aed --- /dev/null +++ b/q4/movies.json @@ -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 + } +] \ No newline at end of file diff --git a/q4/q4_1/movies.json b/q4/q4_1/movies.json new file mode 100644 index 0000000..aca6aed --- /dev/null +++ b/q4/q4_1/movies.json @@ -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 + } +] \ No newline at end of file diff --git a/q4/q4_1/q4_1.py b/q4/q4_1/q4_1.py index b8927e9..5c82852 100644 --- a/q4/q4_1/q4_1.py +++ b/q4/q4_1/q4_1.py @@ -1,6 +1,16 @@ import matplotlib.pyplot as plt import json -with open ("movies.json","r",encoding='utf-8') as f: - print(f) -genre_count=() -plt.bar \ No newline at end of file +movies= json.load(open('movies.json',encoding='utf-8')) +genres= {} +for m in movies: + 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) diff --git a/q4/q4_1/q4_1_bar.png b/q4/q4_1/q4_1_bar.png new file mode 100644 index 0000000..81ecd2f Binary files /dev/null and b/q4/q4_1/q4_1_bar.png differ diff --git a/q4/q4_2/q4_2.py b/q4/q4_2/q4_2.py new file mode 100644 index 0000000..a5309b6 --- /dev/null +++ b/q4/q4_2/q4_2.py @@ -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) diff --git a/q4/q4_2/q4_2_scatter.png b/q4/q4_2/q4_2_scatter.png new file mode 100644 index 0000000..061b8ed Binary files /dev/null and b/q4/q4_2/q4_2_scatter.png differ diff --git a/q4/q4_3a/q4-3a.py b/q4/q4_3a/q4-3a.py new file mode 100644 index 0000000..273225e --- /dev/null +++ b/q4/q4_3a/q4-3a.py @@ -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) + diff --git a/q4/q4_3a/q4_3a_hist.png b/q4/q4_3a/q4_3a_hist.png new file mode 100644 index 0000000..e19911e Binary files /dev/null and b/q4/q4_3a/q4_3a_hist.png differ diff --git a/q4/q4_3b/q4_3b.py b/q4/q4_3b/q4_3b.py new file mode 100644 index 0000000..c98fee2 --- /dev/null +++ b/q4/q4_3b/q4_3b.py @@ -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) + \ No newline at end of file diff --git a/q4/q4_3b/q4_3b_hist.png b/q4/q4_3b/q4_3b_hist.png new file mode 100644 index 0000000..ac4c548 Binary files /dev/null and b/q4/q4_3b/q4_3b_hist.png differ