Skip to content

Commit 0ac6d62

Browse files
committed
Re-add grid functions after deprecation of dependency
1 parent c24818d commit 0ac6d62

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

gripf1/analysis/lap_time_chart.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ class LapTimeChart(TimeSeriesPlot):
3838

3939
def __init__(self, title_session: fastf1.core.Session, driver: gripf1.core.Driver,
4040
excluded_laps: list = None, legend: bool = False, mark_sc: bool = False, # Optional parameters
41-
mark_vsc: bool = False, mark_yellow_flag: bool = False): # Optional parameters
41+
mark_vsc: bool = False, mark_yellow_flag: bool = False, # Optional parameters
42+
minor_x_ticks: bool = 2, minor_y_ticks: bool = 0): # Optional parameters
4243
x_label = "Lap Number"
4344
y_label = "Lap Time [min:sec.ms]"
4445
title = driver.name + " Lap Time Progression"
4546
super().__init__(x_label, y_label, title, title_session, legend)
4647
self.mark_laps(driver, mark_sc, mark_vsc, mark_yellow_flag)
4748
self.add_driver(driver, excluded_laps)
49+
self.add_grid_lines(minor_x_ticks, minor_y_ticks)
4850

4951
def add_driver(self, driver: gripf1.core.Driver,
5052
excluded_laps: list = None): # Optional parameters

gripf1/analysis/speed_chart.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ class SpeedChart(TimeSeriesPlot):
2929
3030
"""
3131

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

4244
def add_lap(self, driver: gripf1.core.Driver, lap_number: int = 0):
4345
"""

gripf1/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ def get_driver_laps(self, session) -> fastf1.core.Laps:
8989
:param session: Session object to get the data from
9090
:return: fastf1.core.Laps
9191
"""
92-
return session.laps.pick_driver(self.abbr)
92+
return session.laps.pick_drivers(self.abbr)

gripf1/plotting/time_series_plot.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pandas
33
import numpy as np
44
from matplotlib import pyplot as plt
5+
from matplotlib.ticker import MultipleLocator
56

67

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

114+
def add_grid_lines(self,
115+
minor_x_ticks: float = 0, minor_y_ticks: float = 0): # Optional parameters
116+
"""
117+
Adds grid lines to the plot
118+
:return:
119+
"""
120+
121+
# Set x-axis ticks every 2 laps
122+
if minor_x_ticks > 0:
123+
self.ax.xaxis.set_minor_locator(MultipleLocator(minor_x_ticks))
124+
125+
# Set y-axis ticks every 0.5 seconds
126+
if minor_y_ticks > 0:
127+
self.ax.yaxis.set_minor_locator(MultipleLocator(minor_y_ticks))
128+
129+
# Display grid lines
130+
plt.grid(which='minor', alpha=0.2)
131+
plt.grid(which='major', alpha=0.5)
132+
113133
def plot(self):
114134
"""
115135
Displays the plot
@@ -118,5 +138,5 @@ def plot(self):
118138

119139
if self.legend:
120140
self.ax.legend()
121-
plt.grid(color='gray')
141+
122142
plt.show()

0 commit comments

Comments
 (0)