Skip to content

Commit

Permalink
Re-add grid functions after deprecation of dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
LuDomMedia committed Nov 26, 2024
1 parent c24818d commit 0ac6d62
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 3 additions & 1 deletion gripf1/analysis/lap_time_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class LapTimeChart(TimeSeriesPlot):

def __init__(self, title_session: fastf1.core.Session, driver: gripf1.core.Driver,
excluded_laps: list = None, legend: bool = False, mark_sc: bool = False, # Optional parameters
mark_vsc: bool = False, mark_yellow_flag: bool = False): # Optional parameters
mark_vsc: bool = False, mark_yellow_flag: bool = False, # Optional parameters
minor_x_ticks: bool = 2, minor_y_ticks: bool = 0): # Optional parameters
x_label = "Lap Number"
y_label = "Lap Time [min:sec.ms]"
title = driver.name + " Lap Time Progression"
super().__init__(x_label, y_label, title, title_session, legend)
self.mark_laps(driver, mark_sc, mark_vsc, mark_yellow_flag)
self.add_driver(driver, excluded_laps)
self.add_grid_lines(minor_x_ticks, minor_y_ticks)

def add_driver(self, driver: gripf1.core.Driver,
excluded_laps: list = None): # Optional parameters
Expand Down
6 changes: 4 additions & 2 deletions gripf1/analysis/speed_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ class SpeedChart(TimeSeriesPlot):
"""

def __init__(self, title_session: fastf1.core.Session, driver: gripf1.core.Driver, lap_number: int = 0,
legend: bool = False): # Optional parameters
def __init__(self, title_session: fastf1.core.Session, driver: gripf1.core.Driver,
lap_number: int = 0, legend: bool = False, # Optional parameters
minor_x_ticks: float = 0, minor_y_ticks: float = 10): # Optional parameters
x_label = "Time [s]"
y_label = "Speed [km/h]"
title = driver.name + " Speed Analysis | Lap " + str(lap_number)
if lap_number == 0:
title = driver.name + " Speed Analysis | Fastest Lap"
super().__init__(x_label, y_label, title, title_session, legend)
self.add_lap(driver, lap_number)
self.add_grid_lines(minor_x_ticks, minor_y_ticks)

def add_lap(self, driver: gripf1.core.Driver, lap_number: int = 0):
"""
Expand Down
2 changes: 1 addition & 1 deletion gripf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ def get_driver_laps(self, session) -> fastf1.core.Laps:
:param session: Session object to get the data from
:return: fastf1.core.Laps
"""
return session.laps.pick_driver(self.abbr)
return session.laps.pick_drivers(self.abbr)
22 changes: 21 additions & 1 deletion gripf1/plotting/time_series_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pandas
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import MultipleLocator


class TimeSeriesPlot:
Expand Down Expand Up @@ -110,6 +111,25 @@ def mark_x_axis(self, lap: int, color: str, label: str, alpha: float = 0.3, line
else:
self.ax.axvline(x=lap, color=color, alpha=alpha, linewidth=linewidth, label=label, zorder=2)

def add_grid_lines(self,
minor_x_ticks: float = 0, minor_y_ticks: float = 0): # Optional parameters
"""
Adds grid lines to the plot
:return:
"""

# Set x-axis ticks every 2 laps
if minor_x_ticks > 0:
self.ax.xaxis.set_minor_locator(MultipleLocator(minor_x_ticks))

# Set y-axis ticks every 0.5 seconds
if minor_y_ticks > 0:
self.ax.yaxis.set_minor_locator(MultipleLocator(minor_y_ticks))

# Display grid lines
plt.grid(which='minor', alpha=0.2)
plt.grid(which='major', alpha=0.5)

def plot(self):
"""
Displays the plot
Expand All @@ -118,5 +138,5 @@ def plot(self):

if self.legend:
self.ax.legend()
plt.grid(color='gray')

plt.show()

0 comments on commit 0ac6d62

Please sign in to comment.