-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: reimplement plotting module (#585)
- Loading branch information
Showing
48 changed files
with
3,278 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
from fastf1.plotting._constants import Constants | ||
|
||
|
||
n = len(Constants) # total number of years | ||
|
||
# dynamically adjust figure size depending on number of required subplots | ||
fig = plt.figure(figsize=(10, 3 * n)) | ||
|
||
# slightly paranoid, sort years explicitly (order is not necessarily | ||
# guaranteed in the internal code) | ||
years_sorted = [str(year) for year in | ||
sorted((int(year) for year in Constants.keys()), reverse=True)] | ||
|
||
# generate one axis/graphic for each year | ||
for i, year in enumerate(years_sorted): | ||
teams = Constants[year].Teams | ||
|
||
ax = fig.add_subplot(n, 1, i + 1) | ||
|
||
x_labels = list() | ||
x_ranges = list() | ||
default_colors = list() | ||
official_colors = list() | ||
|
||
for j, (name, team) in enumerate(teams.items()): | ||
x_labels.append(team.ShortName) | ||
default_colors.append(team.TeamColor.FastF1) | ||
official_colors.append(team.TeamColor.Official) | ||
|
||
x_ranges.append((j + 0.5, 1)) | ||
|
||
# draw color rectangles as horizontal bar graph | ||
ax.broken_barh(x_ranges, (0.5, 0.9), facecolors=official_colors) | ||
ax.broken_barh(x_ranges, (1.5, 0.9), facecolors=default_colors) | ||
|
||
# configure y axis and label | ||
ax.set_ylim((0.5, 2.5)) | ||
ax.set_yticks([1, 2]) | ||
ax.set_yticklabels(['official', 'default']) | ||
|
||
# configure x axis and label | ||
ax.set_xlim((0.5, len(x_ranges) + 0.5)) | ||
ax.set_xticks(range(1, len(x_labels) + 1)) | ||
ax.set_xticklabels(x_labels) | ||
|
||
# disable frame around axis | ||
ax.spines['top'].set_visible(False) | ||
ax.spines['bottom'].set_visible(False) | ||
ax.spines['right'].set_visible(False) | ||
ax.spines['left'].set_visible(False) | ||
|
||
# disable tick markers everywhere, label x axis at the top | ||
ax.tick_params(top=False, labeltop=True, bottom=False, labelbottom=False, | ||
left=False, labelleft=True, right=False, labelright=False) | ||
|
||
# set tick label text color (grey, so it works on light and dark theme and | ||
# isn't too distracting next to the colors) | ||
ax.tick_params(colors='#787878') | ||
|
||
# set background color within axes | ||
# (transparent, fallback white if transparency not supported) | ||
ax.set_facecolor('#ffffff00') | ||
|
||
# set axes title (grey, so it works on light and dark theme and | ||
# isn't too distracting next to the colors) | ||
ax.set_title(year, color='#787878') | ||
|
||
# set background color for figure/margins around axes | ||
# (transparent, fallback white if transparency not supported) | ||
fig.patch.set_facecolor('#ffffff00') | ||
|
||
# adjust margins between and around axes | ||
plt.subplots_adjust(top=0.95, bottom=0.05, left=0.1, right=0.95, hspace=0.5) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ Release Notes | |
|
||
Looking for :ref:`previous-release-notes`? | ||
|
||
.. include:: v3.3.x.rst | ||
.. include:: v3.4.x.rst | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ Release Notes for Older Versions | |
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
v3.3.x | ||
v3.2.x | ||
v3.1.x | ||
v3.0.x | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
What's new in v3.4.0 | ||
-------------------- | ||
|
||
(released dd/mm/yyyy) | ||
|
||
|
||
New Features | ||
^^^^^^^^^^^^ | ||
|
||
|
||
|
||
Bug Fixes | ||
^^^^^^^^^ | ||
|
||
|
||
Deprecations | ||
^^^^^^^^^^^^ | ||
|
||
- The following module level properties of :mod:`fastf1.plotting` have been | ||
deprecated: | ||
:attr:`~fastf1.plotting.COMPOUND_COLORS`, | ||
:attr:`~fastf1.plotting.DRIVER_TRANSLATE`, | ||
:attr:`~fastf1.plotting.TEAM_COLORS`, | ||
:attr:`~fastf1.plotting.TEAM_TRANSLATE`, | ||
:attr:`~fastf1.plotting.COLOR_PALETTE` | ||
|
||
|
||
- The following functions in :mod:`fastf1.plotting` have been deprecated: | ||
:func:`~fastf1.plotting.driver_color`, | ||
:func:`~fastf1.plotting.team_color` | ||
|
||
|
||
Removals | ||
^^^^^^^^ | ||
|
||
- ``fastf1.plotting.lapnumber_axis`` has been removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,158 @@ | ||
Plotting - :mod:`fastf1.plotting` | ||
================================= | ||
|
||
Helper functions for creating data plots. | ||
|
||
:mod:`fastf1.plotting` provides optional functionality with the intention of | ||
making it easy to create nice plots. | ||
|
||
This module mainly offers: | ||
- team names and colors | ||
- driver names and driver abbreviations | ||
- Matplotlib integration and helper functions | ||
|
||
FastF1 focuses on plotting with Matplotlib or related libraries like Seaborn. | ||
If you wish to use these libraries, it is highly recommended to enable | ||
extend support for these by calling :func:`~fastf1.plotting.setup_mpl`. | ||
|
||
|
||
Team Colormaps | ||
-------------- | ||
|
||
Currently, two team colormaps are supported. Each colormap provides one color | ||
for each team. All functions that return colors for teams or drivers accept an | ||
optional ``colormap`` argument. If this argument is not provided, the default | ||
colormap is used. The default colormap can be changed by using | ||
:func:`~fastf1.plotting.set_default_colormap`. | ||
|
||
The ``'fastf1'`` colormap is FastF1's default colormap. These colors are teams' | ||
primary colors or accent colors as they are used by the teams on their website | ||
or in promotional material. The colors are chosen to maximize readability in | ||
plots by creating a stronger contrast while still being associated with the | ||
team. Colors are constant over the course of a season. | ||
|
||
The ``'official'`` colormap contains the colors exactly as they are used by | ||
F1 in official graphics and in the TV broadcast. Those colors are often | ||
slightly muted. While that makes them more pleasing to look at in some graphics, | ||
it also reduces the contrast between colors which is often bad for | ||
readability of plots. These colors may change during the season if they are | ||
updated by F1. | ||
|
||
See here for a complete list of all colors: :ref:`Team-Colormaps-Overview` | ||
|
||
|
||
.. note:: **Driver Colors** | ||
|
||
Previously, individual colors for each driver were provided. This is no | ||
longer the case. The driver color is now equivalent to the team color, | ||
meaning that drivers from the same team have the exact same color. This | ||
change was made because different colors for 20 drivers end up looking | ||
very similar in a lot of cases. Therefore, it is not a good solution to | ||
use driver specific colors to distinguish between different drivers. Other | ||
means of plot styling should be used instead. | ||
|
||
|
||
|
||
Overview | ||
-------- | ||
|
||
|
||
Configuration and Setup | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: fastf1.plotting | ||
:noindex: | ||
:no-members: | ||
:autosummary: | ||
:autosummary-members: | ||
setup_mpl | ||
|
||
|
||
Get Colors, Names and Abbreviations for Drivers or Teams | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: fastf1.plotting | ||
:noindex: | ||
:no-members: | ||
:autosummary: | ||
:autosummary-members: | ||
get_compound_color, | ||
get_driver_abbreviation, | ||
get_driver_abbreviations_by_team, | ||
get_driver_color, | ||
get_driver_name, | ||
get_driver_names_by_team, | ||
get_driver_style, | ||
get_team_color, | ||
get_team_name, | ||
get_team_name_by_driver | ||
|
||
|
||
List all Names and Abbreviations for Drivers/Teams in a Session | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: fastf1.plotting | ||
:noindex: | ||
:no-members: | ||
:autosummary: | ||
:autosummary-members: | ||
get_compound_mapping, | ||
get_driver_color_mapping, | ||
list_compounds, | ||
list_driver_abbreviations, | ||
list_driver_names, | ||
list_team_names | ||
|
||
|
||
Plot Styling | ||
^^^^^^^^^^^^ | ||
|
||
.. automodule:: fastf1.plotting | ||
:noindex: | ||
:no-members: | ||
:autosummary: | ||
:autosummary-members: | ||
add_sorted_driver_legend, | ||
set_default_colormap | ||
|
||
|
||
Advanced Functionality | ||
^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automodule:: fastf1.plotting | ||
:noindex: | ||
:no-members: | ||
:autosummary: | ||
:autosummary-members: | ||
override_team_constants | ||
|
||
|
||
Deprecated Functionality | ||
^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
The following module-level attributes are deprecated since version 3.4.0 and | ||
will be removed in a future release. | ||
|
||
|
||
.. automodule:: fastf1.plotting | ||
:noindex: | ||
:no-members: | ||
:autosummary: | ||
:autosummary-members: | ||
driver_color, | ||
lapnumber_axis, | ||
team_color, | ||
COMPOUND_COLORS, | ||
DRIVER_TRANSLATE, | ||
DRIVER_COLORS, | ||
TEAM_COLORS, | ||
TEAM_TRANSLATE, | ||
COLOR_PALETTE | ||
|
||
|
||
|
||
Plotting API Reference | ||
---------------------- | ||
|
||
.. automodule:: fastf1.plotting | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
:orphan: | ||
|
||
.. _Team-Colormaps-Overview: | ||
|
||
Overview over Team Colormaps | ||
---------------------------- | ||
|
||
(Note that the official colors that are shown here may be different from those | ||
that are returned by FastF1 for some sessions as these colors may be updated | ||
by F1 during the season.) | ||
|
||
.. plot:: _plots/colormap_overview.py | ||
:include-source: False |
Oops, something went wrong.