Skip to content
Snippets Groups Projects
DataPlotter.py 1.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • Lennard Geese's avatar
    T
    Lennard Geese committed
    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, raceName: str):
    
    Lennard Geese's avatar
    T
    Lennard Geese committed
    
            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')
    
    Lennard Geese's avatar
    T
    Lennard Geese committed
    
            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()