-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_annual_score.py
More file actions
63 lines (50 loc) · 1.79 KB
/
plot_annual_score.py
File metadata and controls
63 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from datetime import datetime
from collections import deque
from json import load
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
with open('bgm_anime_dataset.json', 'r', encoding='utf8') as f:
data = load(f)
air_dates = [
datetime.fromisoformat(bangumi['air_date']) for bangumi in data
if not bangumi['air_date'].startswith('0')
]
scores = np.array(
[bangumi['rating']['score'] for bangumi in data
if not bangumi['air_date'].startswith('0')],
dtype=np.float64
)
rc('font', family='Sarasa Gothic SC', size=14)
fig, ax = plt.subplots()
ax.scatter(air_dates, scores, c='#fca2ae')
scores = {}
for bangumi in data:
if bangumi['air_date'].startswith('0'):
continue
year = datetime.fromisoformat(bangumi['air_date']).year
if year < 1990:
continue
if year not in scores:
scores[year] = deque()
scores[year].append(bangumi['rating']['score'])
mean_scores = {}
median_scores = {}
for year, scores in scores.items():
scores_arr = np.array([scores], dtype=np.float64)
mean_scores[year] = np.mean(scores)
median_scores[year] = np.median(scores)
mean_scores = list(zip(*sorted(mean_scores.items(), key=lambda x: x[0])))
mean_scores[0] = [datetime(y, 1, 1) for y in mean_scores[0]]
median_scores = list(zip(*sorted(median_scores.items(), key=lambda x: x[0])))
median_scores[0] = [datetime(y, 1, 1) for y in median_scores[0]]
ax.plot(*mean_scores, c='#06b0ff')
# ax.plot(*median_scores, c='#18ff52')
ax.yaxis.set_ticks([x / 2 for x in range(2, 20, 1)])
ax.xaxis.set_ticks([datetime(y, 1, 1) for y in range(1930, 2021, 10)])
ax.grid(True, axis='both')
ax.set_xlabel('放送时间')
ax.set_ylabel('评分')
ax.set_title('Bangumi 动画 放送时间—评分 分布(蓝线是每年平均分)')
fig.tight_layout()
plt.show()