-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
116 lines (88 loc) · 4.49 KB
/
plotter.py
File metadata and controls
116 lines (88 loc) · 4.49 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import json
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.ticker import AutoMinorLocator
# def plot_graphs(filename, nrows, ncols):
# with open(filename, "r") as f:
# data = json.load(f)
# sns.set_theme(style="whitegrid")
# methods = [
# ("Euler", data["euler_x"], data["euler_y1"], data["euler_y2"]),
# ("Euler_rec", data["euler_rec_x"], data["euler_rec_y1"], data["euler_rec_y2"]),
# ("RK2", data["rk2_x"], data["rk2_y1"], data["rk2_y2"]),
# ("RK4", data["rk4_x"], data["rk4_y1"], data["rk4_y2"]),
# ("Adams", data["adams_x"], data["adams_y1"], data["adams_y2"]),
# ("FEuler", data["feuler_x"], data["feuler_y1"], data["feuler_y2"])
# ]
# fig, axes = plt.subplots(nrows, ncols,
# figsize=(ncols * 5, nrows * 4),
# sharey=True)
# # превращаем axes в плоский список для удобства
# axes = axes.flatten()
# for ax, (title, x, y1, y2) in zip(axes, methods):
# sns.lineplot(x=x, y=y1, label="y1", ax=ax)
# sns.lineplot(x=x, y=y2, label="y2", ax=ax)
# ax.set_title(title)
# ax.set_xlabel("x")
# ax.set_ylabel("y")
# ax.legend()
# ax.xaxis.set_minor_locator(AutoMinorLocator(4)) # разобьёт каждый интервал между мажорными делениями на 4 части
# ax.yaxis.set_minor_locator(AutoMinorLocator(4))
# ax.minorticks_on() # включить отображение минорных меток
# ax.grid(which='minor', linewidth=0.5, alpha=0.6)
# #Удаление лишних осей, если есть
# for ax in axes[len(methods):]:
# fig.delaxes(ax)
# plt.tight_layout()
# plt.show()
# plot_graphs("data.json", nrows=2, ncols=3)
def plot_graphs(filename):
with open(filename, "r") as f:
data = json.load(f)
sns.set_theme(style="whitegrid")
euler_x = data["euler_x"]
euler_rec_x = data["euler_rec_x"]
rk2_x = data["rk2_x"]
rk4_x = data["rk4_x"]
adams_x = data["adams_x"]
euler_y1 = data["euler_y1"]
euler_rec_y1 = data["euler_rec_y1"]
rk2_y1 = data["rk2_y1"]
rk4_y1 = data["rk4_y1"]
adams_y1 = data["adams_y1"]
euler_y2 = data["euler_y2"]
euler_rec_y2 = data["euler_rec_y2"]
rk2_y2 = data["rk2_y2"]
rk4_y2 = data["rk4_y2"]
adams_y2 = data["adams_y2"]
# Установка темы и стиля
sns.set_theme(style="whitegrid", palette="muted", font="serif", font_scale=1.2)
# Построение графика
fig, axes = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
sns.lineplot(x=euler_x, y=euler_y1, ax=axes[0], label='euler')
sns.lineplot(x=euler_rec_x, y=euler_rec_y1, ax=axes[0], label='euler_rec')
sns.lineplot(x=rk2_x, y=rk2_y1, ax=axes[0], label='rk2')
sns.lineplot(x=rk4_x, y=rk4_y1, ax=axes[0], label='rk4')
sns.lineplot(x=adams_x, y=adams_y1, ax=axes[0], label='adams')
sns.lineplot(x=euler_x, y=euler_y2, ax=axes[1], label='euler')
sns.lineplot(x=euler_rec_x, y=euler_rec_y2, ax=axes[1], label='euler_rec')
sns.lineplot(x=rk2_x, y=rk2_y2, ax=axes[1], label='rk2')
sns.lineplot(x=rk4_x, y=rk4_y2, ax=axes[1], label='rk4')
sns.lineplot(x=adams_x, y=adams_y2, ax=axes[1], label='adams')
axes[0].set_title("y1")
axes[1].set_title("y2")
# Настройки графика
plt.xlabel("X", fontsize=14)
plt.ylabel("value", fontsize=14)
axes[0].xaxis.set_minor_locator(AutoMinorLocator(4)) # разобьёт каждый интервал между мажорными делениями на 4 части
axes[0].yaxis.set_minor_locator(AutoMinorLocator(4))
axes[0].minorticks_on() # включить отображение минорных меток
axes[0].grid(which='minor', linewidth=0.5, alpha=0.6)
axes[1].xaxis.set_minor_locator(AutoMinorLocator(4)) # разобьёт каждый интервал между мажорными делениями на 4 части
axes[1].yaxis.set_minor_locator(AutoMinorLocator(4))
axes[1].minorticks_on() # включить отображение минорных меток
axes[1].grid(which='minor', linewidth=0.5, alpha=0.6)
plt.tight_layout()
# Отображение графика
plt.show()
plot_graphs("data.json")