Newer
Older
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
import math
from abc import ABC
from typing import List
import matplotlib.pyplot as plt
import numpy as np
from fastf1.core import Session, Lap
from DataHandler import DataHandler
class DataPlotter(DataHandler):
def plotOvertakesWithTireChangeWindow(self, overtakesPerLap: List[int], earliestTireChange: int, latestTireChange: int):
overtakesPerLap.insert(0, 0) # Insert 0th lap, which cannot have overtakes
laps: int = len(overtakesPerLap)
figure, axis = plt.subplots(figsize=(8.0, 4.9))
axis.plot(overtakesPerLap)
axis.set_xlabel('Lap')
axis.set_ylabel('Position changes in lap')
major_ticks_laps = np.arange(0, laps, 5)
major_ticks_overtakes = np.arange(0, max(overtakesPerLap) + 1, 5)
minor_ticks_laps = np.arange(0, laps, 1)
minor_ticks_overtakes = np.arange(0, max(overtakesPerLap) + 1, 1)
axis.set_xticks(major_ticks_laps)
axis.set_xticks(minor_ticks_laps, minor=True)
axis.set_yticks(major_ticks_overtakes)
axis.set_yticks(minor_ticks_overtakes, minor=True)
# And a corresponding grid
axis.grid(which='both')
# Or if you want different settings for the grids:
axis.grid(which='minor', alpha=0.2)
axis.grid(which='major', alpha=0.5)
axis.legend(bbox_to_anchor=(1.0, 1.02))
plt.tight_layout()
plt.show()