G

Untitled

public
Guest May 13, 2025 Never 8
Clone
1
import matplotlib.pyplot as plt
2
import matplotlib.dates as mdates
3
from datetime import datetime
4
5
# Данные приливов
6
ports_data = {
7
"Копенгаген": [
8
("00:00", 0.04),
9
("03:00", 0.08),
10
("06:00", 0.11),
11
("09:00", 0.08),
12
("12:00", 0.02),
13
("15:00", -0.03),
14
("18:00", 0.00),
15
("21:00", 0.06),
16
],
17
"Рённе": [
18
("00:00", 0.02),
19
("03:00", 0.04),
20
("06:00", 0.06),
21
("09:00", 0.04),
22
("12:00", 0.01),
23
("15:00", 0.00),
24
("18:00", 0.02),
25
("21:00", 0.04),
26
],
27
"Лиепая": [
28
("00:00", 0.05),
29
("03:00", 0.10),
30
("06:00", 0.17),
31
("09:00", 0.10),
32
("12:00", 0.00),
33
("15:00", -0.12),
34
("18:00", -0.05),
35
("21:00", 0.05),
36
],
37
}
38
39
# Построение графиков
40
fig, axs = plt.subplots(3, 1, figsize=(10, 12), sharex=True)
41
fig.suptitle('График приливов на 15.07.2024', fontsize=16)
42
43
for ax, (port, data) in zip(axs, ports_data.items()):
44
times = [datetime.strptime(t, "%H:%M") for t, _ in data]
45
heights = [h for _, h in data]
46
ax.plot(times, heights, marker='o', label=port)
47
ax.set_title(port)
48
ax.set_ylabel("Высота (м)")
49
ax.grid(True)
50
ax.legend()
51
ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
52
53
axs[-1].set_xlabel("Время (часы)")
54
55
plt.tight_layout(rect=[0, 0, 1, 0.96])
56
plt.savefig("graph_tides_15_07_2024.png", dpi=300) # Сохраняем график
57
plt.show()