skillcornerviz 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. skillcornerviz-1.0.0/LICENSE +17 -0
  2. skillcornerviz-1.0.0/PKG-INFO +49 -0
  3. skillcornerviz-1.0.0/README.md +23 -0
  4. skillcornerviz-1.0.0/pyproject.toml +36 -0
  5. skillcornerviz-1.0.0/setup.cfg +4 -0
  6. skillcornerviz-1.0.0/setup.py +34 -0
  7. skillcornerviz-1.0.0/src/skillcornerviz/__init__.py +0 -0
  8. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Black.ttf +0 -0
  9. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-BlackItalic.ttf +0 -0
  10. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Bold.ttf +0 -0
  11. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-BoldItalic.ttf +0 -0
  12. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Italic.ttf +0 -0
  13. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Light.ttf +0 -0
  14. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-LightItalic.ttf +0 -0
  15. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Medium.ttf +0 -0
  16. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-MediumItalic.ttf +0 -0
  17. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Regular.ttf +0 -0
  18. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-Thin.ttf +0 -0
  19. skillcornerviz-1.0.0/src/skillcornerviz/resources/Roboto/Roboto-ThinItalic.ttf +0 -0
  20. skillcornerviz-1.0.0/src/skillcornerviz/resources/__init__.py +0 -0
  21. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/__init__.py +0 -0
  22. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/bar_plot.py +342 -0
  23. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/formating.py +92 -0
  24. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/radar_plot.py +341 -0
  25. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/scatter_plot.py +345 -0
  26. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/summary_table.py +522 -0
  27. skillcornerviz-1.0.0/src/skillcornerviz/standard_plots/swarm_violin_plot.py +284 -0
  28. skillcornerviz-1.0.0/src/skillcornerviz/utils/__init__.py +0 -0
  29. skillcornerviz-1.0.0/src/skillcornerviz/utils/constants.py +231 -0
  30. skillcornerviz-1.0.0/src/skillcornerviz/utils/skillcorner_colors.py +113 -0
  31. skillcornerviz-1.0.0/src/skillcornerviz/utils/skillcorner_game_intelligence_utils.py +349 -0
  32. skillcornerviz-1.0.0/src/skillcornerviz/utils/skillcorner_physical_utils.py +175 -0
  33. skillcornerviz-1.0.0/src/skillcornerviz/utils/skillcorner_utils.py +147 -0
  34. skillcornerviz-1.0.0/src/skillcornerviz.egg-info/PKG-INFO +49 -0
  35. skillcornerviz-1.0.0/src/skillcornerviz.egg-info/SOURCES.txt +37 -0
  36. skillcornerviz-1.0.0/src/skillcornerviz.egg-info/dependency_links.txt +1 -0
  37. skillcornerviz-1.0.0/src/skillcornerviz.egg-info/requires.txt +6 -0
  38. skillcornerviz-1.0.0/src/skillcornerviz.egg-info/top_level.txt +1 -0
  39. skillcornerviz-1.0.0/tests/tests.py +259 -0
@@ -0,0 +1,17 @@
1
+ MIT License
2
+ Copyright (c) 2021 Skillcorner
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+ The above copyright notice and this permission notice shall be included in all
10
+ copies or substantial portions of the Software.
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ SOFTWARE.
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.1
2
+ Name: skillcornerviz
3
+ Version: 1.0.0
4
+ Summary: A Python package for processing and visualizing data SkillCorner data. This enables a user to produce visualizations with the SkillCorner brand style with a minimum of changes
5
+ Home-page: https://github.com/MarkosBont/skillcorner_library_cleanup
6
+ Author: Liam Bailey, Markos Bontozoglou, Micheal Nanopoulos, SkillCorner
7
+ Author-email: markos.bontozoglou@skillcorner.com
8
+ Project-URL: GitHub, https://github.com/MarkosBont/skillcorner_library_cleanup
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Other Audience
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Operating System :: OS Independent
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: adjustText>=0.7.3
21
+ Requires-Dist: aiohttp>=3.8.4
22
+ Requires-Dist: matplotlib>=3.7.2
23
+ Requires-Dist: numpy>=1.24.2
24
+ Requires-Dist: pandas>=1.5.3
25
+ Requires-Dist: seaborn>=0.11.2
26
+
27
+ # SkillCorner Analysis Library
28
+ The SkillCorner Analysis Library is a Python package that provides functions to create standard visualizations frequently used by the SkillCorner data analysis team. It also includes functions to normalize SkillCorner data in various ways. This package is designed to streamline the data analysis process and facilitate the creation of insightful visualizations.
29
+
30
+ ## Package Structure (skillcorner_analysis_lib)
31
+ ![package structure](output/example_plots/package_structure.png)
32
+
33
+ ## Current color usage guide
34
+
35
+ - Background data/players: <span style="color:#D9D9D6">#D9D9D6</span>
36
+ - Primary highlight/target player colour: <span style="color:#00C800">#00C800</span>
37
+ - Secondary highlight/comparison player: <span style="color:#26BF52">#26BF52</span>
38
+ - Axes & texts: <span style="color:#001400">#001400</span>
39
+
40
+ ## Plot Examples
41
+ ### Bar Plot
42
+ ![standard bar plot](output/example_plots/bar_plot.png)
43
+ ### Scatter Plot
44
+ ![standard scatter plot](output/example_plots/scatter_plot.png)
45
+ ### Swarm/Violin Plot
46
+ ![standard scatter plot](output/example_plots/swarm_violin_plot.png)
47
+
48
+ ## Contributing
49
+ If you encounter any issues, have suggestions, or would like to contribute to the SkillCorner Analysis Library, please visit the GitHub repository. We welcome your contributions and appreciate your support in making this package better.
@@ -0,0 +1,23 @@
1
+ # SkillCorner Analysis Library
2
+ The SkillCorner Analysis Library is a Python package that provides functions to create standard visualizations frequently used by the SkillCorner data analysis team. It also includes functions to normalize SkillCorner data in various ways. This package is designed to streamline the data analysis process and facilitate the creation of insightful visualizations.
3
+
4
+ ## Package Structure (skillcorner_analysis_lib)
5
+ ![package structure](output/example_plots/package_structure.png)
6
+
7
+ ## Current color usage guide
8
+
9
+ - Background data/players: <span style="color:#D9D9D6">#D9D9D6</span>
10
+ - Primary highlight/target player colour: <span style="color:#00C800">#00C800</span>
11
+ - Secondary highlight/comparison player: <span style="color:#26BF52">#26BF52</span>
12
+ - Axes & texts: <span style="color:#001400">#001400</span>
13
+
14
+ ## Plot Examples
15
+ ### Bar Plot
16
+ ![standard bar plot](output/example_plots/bar_plot.png)
17
+ ### Scatter Plot
18
+ ![standard scatter plot](output/example_plots/scatter_plot.png)
19
+ ### Swarm/Violin Plot
20
+ ![standard scatter plot](output/example_plots/swarm_violin_plot.png)
21
+
22
+ ## Contributing
23
+ If you encounter any issues, have suggestions, or would like to contribute to the SkillCorner Analysis Library, please visit the GitHub repository. We welcome your contributions and appreciate your support in making this package better.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "skillcornerviz"
7
+ version = "1.0.0"
8
+ authors = [
9
+ {name="Liam Bailey"},
10
+ {name="Markos Bontozoglou"},
11
+ {name="Micheal Nanopoulos"},
12
+ {name="SkillCorner"}
13
+ ]
14
+ description = " A Python package for processing and visualizing data SkillCorner data. This enables a user to produce visualizations with the SkillCorner brand style with a minimum of changes"
15
+ readme = "README.md"
16
+ requires-python = ">=3.8"
17
+ classifiers = ["Development Status :: 4 - Beta", "Intended Audience :: Other Audience",
18
+ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9", "Operating System :: OS Independent"]
21
+ dependencies = ['adjustText>=0.7.3',
22
+ 'aiohttp>=3.8.4',
23
+ 'matplotlib>=3.7.2',
24
+ 'numpy>=1.24.2',
25
+ 'pandas>=1.5.3',
26
+ 'seaborn>=0.11.2']
27
+
28
+ [project.urls]
29
+ GitHub = "https://github.com/MarkosBont/skillcorner_library_cleanup"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+ include = ["skillcornerviz", "skillcornerviz.*"]
34
+
35
+
36
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,34 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='skillcornerviz',
5
+ version='1.0.0',
6
+
7
+ url='https://github.com/MarkosBont/skillcorner_library_cleanup',
8
+ author='Liam Michael Bailey',
9
+ author_email='markos.bontozoglou@skillcorner.com',
10
+
11
+ packages=find_packages(include=['skillcornerviz', 'skillcornerviz.*']),
12
+
13
+ package_data={'skillcornerviz': ['resources/Roboto/Roboto-Black.ttf',
14
+ 'resources/Roboto/Roboto-BlackItalic.ttf',
15
+ 'resources/Roboto/Roboto-Bold.ttf',
16
+ 'resources/Roboto/Roboto-BoldItalic.ttf',
17
+ 'resources/Roboto/Roboto-Italic.ttf',
18
+ 'resources/Roboto/Roboto-Light.ttf',
19
+ 'resources/Roboto/Roboto-LightItalic.ttf',
20
+ 'resources/Roboto/Roboto-Medium.ttf',
21
+ 'resources/Roboto/Roboto-MediumItalic.ttf',
22
+ 'resources/Roboto/Roboto-Regular.ttf',
23
+ 'resources/Roboto/Roboto-Thin.ttf',
24
+ 'resources/Roboto/Roboto-ThinItalic.ttf']},
25
+
26
+ install_requires=['adjustText>=0.7.3',
27
+ 'aiohttp>=3.8.4',
28
+ 'matplotlib>=3.7.2',
29
+ 'numpy>=1.24.2',
30
+ 'pandas>=1.5.3',
31
+ 'seaborn>=0.11.2'],
32
+
33
+ include_package_data=True,
34
+ )
File without changes
@@ -0,0 +1,342 @@
1
+ """
2
+ Liam Bailey
3
+ 16/03/2023
4
+ Bar plot
5
+ The plot_bar_chart function is used to generate a bar chart based on the given data.
6
+ It accepts various parameters such as the DataFrame (df) containing the metric data,
7
+ the column to plot on the axis (x_value), labels for the axis (label) and the
8
+ unit of measurement (unit), groups of players to highlight (primary_highlight_group
9
+ and secondary_highlight_group), colors for highlighting (primary_highlight and
10
+ secondary_highlight_color), and other optional customization parameters.
11
+ """
12
+ import matplotlib.pyplot as plt
13
+
14
+ from matplotlib.ticker import EngFormatter
15
+ import pandas as pd
16
+ from skillcornerviz.utils.constants import BASE_COLOR, PRIMARY_HIGHLIGHT_COLOR, SECONDARY_HIGHLIGHT_COLOR, \
17
+ DARK_PRIMARY_HIGHLIGHT_COLOR, DARK_SECONDARY_HIGHLIGHT_COLOR, DARK_BASE_COLOR
18
+ from skillcornerviz.utils.constants import TEXT_COLOR
19
+ from pkg_resources import resource_filename
20
+ from matplotlib import font_manager as fm
21
+ import matplotlib.patheffects as pe
22
+
23
+ fonts = ['resources/Roboto/Roboto-Black.ttf',
24
+ 'resources/Roboto/Roboto-BlackItalic.ttf',
25
+ 'resources/Roboto/Roboto-Bold.ttf',
26
+ 'resources/Roboto/Roboto-BoldItalic.ttf',
27
+ 'resources/Roboto/Roboto-Italic.ttf',
28
+ 'resources/Roboto/Roboto-Light.ttf',
29
+ 'resources/Roboto/Roboto-LightItalic.ttf',
30
+ 'resources/Roboto/Roboto-Medium.ttf',
31
+ 'resources/Roboto/Roboto-MediumItalic.ttf',
32
+ 'resources/Roboto/Roboto-Regular.ttf',
33
+ 'resources/Roboto/Roboto-Thin.ttf',
34
+ 'resources/Roboto/Roboto-ThinItalic.ttf']
35
+
36
+ for f in fonts:
37
+ filepath = resource_filename('skillcornerviz', f)
38
+ fm.fontManager.addfont(filepath)
39
+ plt.rcParams["font.family"] = "Roboto"
40
+
41
+
42
+ def plot_bar_chart(df,
43
+ metric,
44
+ label=None,
45
+ unit=None,
46
+ primary_highlight_group=None,
47
+ secondary_highlight_group=None,
48
+ primary_highlight_color=PRIMARY_HIGHLIGHT_COLOR,
49
+ secondary_highlight_color=SECONDARY_HIGHLIGHT_COLOR,
50
+ data_point_id='player_name',
51
+ data_point_label='player_name',
52
+ plot_title=None,
53
+ base_color=BASE_COLOR,
54
+ add_bar_values=False,
55
+ figsize=(8, 4),
56
+ lim=None,
57
+ order=None,
58
+ vertical=False,
59
+ rotation=90,
60
+ fontsize=7,
61
+ dark_mode=False):
62
+ """
63
+ Plot a bar chart using the given data.
64
+
65
+ Parameters
66
+ ----------
67
+ df : DataFrame
68
+ Metric DataFrame.
69
+ metric : str
70
+ The column in df we want to plot on the x-axis.
71
+ label : str, optional
72
+ The label for the x-axis. This should reflect what the x_value is.
73
+ unit : str, optional
74
+ If we want to add a unit to the axis values. For example % or km/h.
75
+ primary_highlight_group : list, optional
76
+ A group of players to label & highlight in Primary Color
77
+ secondary_highlight_group : list, optional
78
+ A group of players to label & highlight in Secondary Color.
79
+ primary_highlight_color : str, optional
80
+ The color for primary highlighted players (default: 'PHYSICAL PITCH').
81
+ secondary_highlight_color : str, optional
82
+ The color for secondary highlighted players (default: 'PHYSICAL PITCH S60' from SkillCorner's Palette).
83
+ data_point_id : str, optional
84
+ The identifier column for each data point (default: 'player_name').
85
+ data_point_label : str, optional
86
+ The label column for each data point (default: 'player_name').
87
+ plot_title : str, optional
88
+ The title of the plot.
89
+ base_color : str, optional
90
+ The base color for the bars (default: 'INNOVATION' from SkillCorner's Palette).
91
+ figsize : tuple, optional
92
+ Tuple (x, y) that defines the dimensions of the figure (default: (8, 4)).
93
+ lim: tuple, optional
94
+ Tuple (x, y) that defines the axis limits
95
+ order : list, optional
96
+ List that orders the axis (dimensional data) (default: None)
97
+ vertical: bool, optional
98
+ Orients the chart vertically or horizontally. (default: False)
99
+ rotation: int, optional
100
+ Rotates the labels if vertical=True is used. (default: 90)
101
+ fontsize: int, optional
102
+ Sets the fontsize used for texts.
103
+
104
+ Returns
105
+ -------
106
+ fig : matplotlib.figure.Figure
107
+ The generated figure.
108
+ ax : matplotlib.axes.Axes
109
+ The generated axes.
110
+
111
+ """
112
+ # Error Handling
113
+
114
+ if metric not in df.columns:
115
+ raise ValueError("The metric you have entered is not in the DataFrame")
116
+
117
+
118
+ if dark_mode:
119
+ background_color = TEXT_COLOR
120
+ primary_highlight_color = DARK_PRIMARY_HIGHLIGHT_COLOR
121
+ secondary_highlight_color = DARK_SECONDARY_HIGHLIGHT_COLOR
122
+ text_color = 'white'
123
+ edge_color = None
124
+ else:
125
+ background_color = 'white'
126
+ text_color = TEXT_COLOR
127
+ edge_color = None
128
+
129
+ if label is None:
130
+ label = unit
131
+
132
+ # Setting the font to our SkillCorner font.
133
+ if primary_highlight_group is None:
134
+ primary_highlight_group = []
135
+ if secondary_highlight_group is None:
136
+ secondary_highlight_group = []
137
+
138
+ # Setting plot size & background.
139
+ fig, ax = plt.subplots(figsize=figsize)
140
+ fig.patch.set_facecolor(background_color)
141
+ ax.set_facecolor(background_color)
142
+
143
+ # Sorting the dataframe based on the metric to plot.
144
+ if order is None:
145
+ if not vertical:
146
+ df = df.sort_values(by=metric)
147
+ else:
148
+ df = df.sort_values(by=metric, ascending=False)
149
+ else:
150
+ df[data_point_id] = pd.Categorical(df[data_point_id], categories=order, ordered=True)
151
+ df = df.sort_values(data_point_id)
152
+ y_pos = range(0, len(df))
153
+
154
+ # Plotting bars.
155
+ if not vertical:
156
+ bars = ax.barh(y_pos,
157
+ df[metric],
158
+ color=DARK_BASE_COLOR if dark_mode else BASE_COLOR,
159
+ edgecolor=edge_color,
160
+ lw=0.5,
161
+ zorder=3,
162
+ alpha=1
163
+ # alpha=0.1 if dark_mode is True, else alpha=1
164
+ )
165
+ # Looping through data & bars to highlight specific players.
166
+ for i, bar in zip(y_pos, bars):
167
+ # If the player has been included in the comparison_players or target_players
168
+ if df[data_point_id].iloc[i] in secondary_highlight_group or \
169
+ df[data_point_id].iloc[i] in primary_highlight_group:
170
+ bar.set_color(secondary_highlight_color)
171
+ bar.set_alpha(1)
172
+
173
+ # If the player has been included in the target_players
174
+ if df[data_point_id].iloc[i] in primary_highlight_group:
175
+ bar.set_color(primary_highlight_color)
176
+
177
+ # Apply to all bars.
178
+ bar.set_edgecolor(edge_color)
179
+ bar.set_linewidth(0.5)
180
+
181
+ if add_bar_values:
182
+ if unit is not None:
183
+ # If a unit has been given, a string with the rounded value is created, including the unit
184
+ str_value = str(round(df[metric].iloc[i], 2)) + ' ' + unit + ' '
185
+ else:
186
+ # If a unit is not given, only the rounded string is created
187
+ str_value = str(round(df[metric].iloc[i], 2)) + ' '
188
+
189
+ # Adding the str_value to the plot
190
+ ax.text(df[metric].iloc[i], i, str_value,
191
+ # Stylistic features for the plot
192
+ ha='right', va='center',
193
+ fontsize=fontsize, fontweight='bold',
194
+ color=background_color if dark_mode else 'white',
195
+ path_effects=[pe.withStroke(linewidth=.75,
196
+ foreground=text_color,
197
+ alpha=1)])
198
+ else:
199
+ if add_bar_values:
200
+ if unit is not None:
201
+ # If a unit has been given, a string with the rounded value is created, including the unit
202
+ str_value = str(round(df[metric].iloc[i], 2)) + ' ' + unit + ' '
203
+ else:
204
+ # If a unit is not given, only the rounded string is created
205
+ str_value = str(round(df[metric].iloc[i], 2)) + ' '
206
+
207
+ # Adding the str_value to the plot
208
+ ax.text(df[metric].iloc[i], i, str_value,
209
+ # Stylistic features for the plot
210
+ ha='right', va='center',
211
+ fontsize=fontsize, fontweight='bold',
212
+ color=text_color,
213
+ path_effects=[pe.withStroke(linewidth=.75,
214
+ foreground=background_color if dark_mode else 'white',
215
+ alpha=1)])
216
+
217
+ # Setting plot elements to #0C1B37.
218
+ ax.spines['left'].set_color(text_color)
219
+ ax.spines['bottom'].set_color(None)
220
+ # Setting y ticks to player names.
221
+ ax.set_yticks(y_pos)
222
+ ax.set_yticklabels(df[data_point_label])
223
+
224
+ # Setting player names for those in comparison or target groups to bold.
225
+ for i, tick_label in enumerate(ax.get_yticklabels()):
226
+ if df[data_point_id].iloc[i] in secondary_highlight_group or \
227
+ df[data_point_id].iloc[i] in primary_highlight_group:
228
+ tick_label.set_fontproperties({'weight': 'bold', 'size': fontsize})
229
+ else:
230
+ tick_label.set_fontproperties({'size': fontsize})
231
+
232
+ # If a unit has been specified, apply it to the x-axis.
233
+ if unit is not None:
234
+ formatter0 = EngFormatter(unit=unit)
235
+ ax.xaxis.set_major_formatter(formatter0)
236
+ # Setting x label.
237
+ ax.set_xlabel(label,
238
+ fontweight='bold',
239
+ fontsize=fontsize,
240
+ labelpad=8)
241
+ # If you give a lim we set it
242
+ if lim is not None:
243
+ ax.set_xlim(lim)
244
+
245
+ elif vertical:
246
+ bars = ax.bar(y_pos,
247
+ df[metric],
248
+ color=base_color,
249
+ edgecolor=text_color,
250
+ lw=0.5,
251
+ zorder=3,
252
+ alpha=1)
253
+ # Looping through data & bars to highlight specific players.
254
+ for i, bar in zip(y_pos, bars):
255
+ # If the player has been included in the comparison_players or target_players
256
+ if df[data_point_id].iloc[i] in secondary_highlight_group or \
257
+ df[data_point_id].iloc[i] in primary_highlight_group:
258
+ bar.set_color(secondary_highlight_color)
259
+
260
+ # If the player has been included in the target_players
261
+ if df[data_point_id].iloc[i] in primary_highlight_group:
262
+ bar.set_color(primary_highlight_color)
263
+
264
+ # Apply to all bars.
265
+ bar.set_edgecolor(text_color)
266
+ bar.set_linewidth(0.5)
267
+
268
+ if add_bar_values:
269
+ if unit is not None:
270
+ str_value = str(round(df[metric].iloc[i], 2)) + ' ' + unit
271
+ else:
272
+ str_value = str(round(df[metric].iloc[i], 2))
273
+
274
+ ax.text(i, df[metric].iloc[i], str_value,
275
+ ha='center', va='bottom',
276
+ fontsize=fontsize, fontweight='bold',
277
+ color=text_color,
278
+ path_effects=[pe.withStroke(linewidth=.75,
279
+ foreground='white',
280
+ alpha=1)])
281
+
282
+ # Setting plot elements to #0C1B37.
283
+ ax.spines['left'].set_color(None)
284
+ ax.spines['bottom'].set_color(text_color)
285
+
286
+ # Setting y ticks to player names.
287
+ ax.set_xticks(y_pos)
288
+ ax.set_xticklabels(df[data_point_label], rotation=rotation)
289
+
290
+ # Setting player names for those in comparison or target groups to bold.
291
+ for i, tick_label in enumerate(ax.get_xticklabels()):
292
+ if df[data_point_id].iloc[i] in secondary_highlight_group or \
293
+ df[data_point_id].iloc[i] in primary_highlight_group:
294
+ tick_label.set_fontproperties({'weight': 'bold', 'size': fontsize})
295
+ else:
296
+ tick_label.set_fontproperties({'size': fontsize})
297
+
298
+ # If a unit has been specified, apply it to the x-axis.
299
+ if unit is not None:
300
+ formatter0 = EngFormatter(unit=unit)
301
+ ax.yaxis.set_major_formatter(formatter0)
302
+ # Setting x label.
303
+ ax.set_ylabel(label,
304
+ fontweight='bold',
305
+ fontsize=fontsize)
306
+ # If you give a lim we set it
307
+ if lim is not None:
308
+ ax.set_ylim(lim)
309
+
310
+ # Hiding the top & right spines.
311
+ ax.spines['top'].set_color('none')
312
+ ax.spines['right'].set_color('none')
313
+
314
+ # Setting axis label style params.
315
+ ax.tick_params(axis='x',
316
+ colors=text_color,
317
+ labelsize=fontsize,
318
+ length=0)
319
+ ax.tick_params(axis='y',
320
+ colors=text_color,
321
+ labelsize=fontsize)
322
+
323
+ ax.yaxis.label.set_color(text_color)
324
+ ax.xaxis.label.set_color(text_color)
325
+
326
+ # Add grid.
327
+ ax.grid(color=text_color,
328
+ axis='both',
329
+ linestyle='--',
330
+ linewidth=0.5,
331
+ alpha=0.25,
332
+ zorder=1)
333
+
334
+ if plot_title is not None:
335
+ ax.set_title(plot_title, fontweight='normal', color=text_color)
336
+
337
+ for k, spine in ax.spines.items():
338
+ spine.set_zorder(10)
339
+ plt.tight_layout()
340
+ plt.show()
341
+
342
+ return fig, ax
@@ -0,0 +1,92 @@
1
+ """
2
+ Michael Nanopoulos
3
+ Simple function that takes an ax, x , and y
4
+
5
+ """
6
+
7
+ from matplotlib.ticker import EngFormatter
8
+ from skillcornerviz.utils.constants import TEXT_COLOR
9
+
10
+
11
+ def standard_ax_formating(ax,
12
+ x_label,
13
+ y_label,
14
+ x_unit=None,
15
+ y_unit=None,
16
+ labelsize=7,
17
+ fontsize=7,
18
+ show_legend=True,
19
+ legend_fontsize=6,
20
+ show_left_spine=False,
21
+ dark_mode=False):
22
+ """
23
+ Function to format the appearance of a matplotlib axis in a standardized way.
24
+
25
+ Args:
26
+ ax (matplotlib.axis.Axis): The axis object to be formatted.
27
+ x_label (str): The label for the x-axis.
28
+ y_label (str): The label for the y-axis.
29
+ x_unit (str, optional): The unit for the values on the x-axis.
30
+ y_unit (str, optional): The unit for the values on the y-axis.
31
+ labelsize (int, optional): The font size of the axis labels.
32
+ fontsize (int, optional): The font size of the tick labels on the axes.
33
+ show_legend (bool, optional): Whether to show the legend on the plot.
34
+ legend_fontsize (int, optional): The font size of the legend labels.
35
+ show_left_spine (bool, optional): Whether to show the left spine of the plot.
36
+ """
37
+
38
+ color = 'white' if dark_mode else TEXT_COLOR
39
+ # Set x-axis label properties
40
+ ax.set_xlabel(x_label, fontweight='bold', fontsize=labelsize, color=color)
41
+ # Set y-axis label properties
42
+ ax.set_ylabel(y_label, fontweight='bold', fontsize=labelsize, color=color)
43
+
44
+ # Set spine colors
45
+ ax.spines['bottom'].set_color(color)
46
+ ax.spines['top'].set_color('none')
47
+ ax.spines['right'].set_color('none')
48
+ ax.spines['left'].set_color('none')
49
+ if show_left_spine:
50
+ ax.spines['left'].set_color(color)
51
+
52
+ # Set tick parameters for x-axis and y-axis
53
+ ax.tick_params(axis='x', colors=color, labelsize=fontsize)
54
+ ax.tick_params(axis='y', colors=color, labelsize=fontsize, length=0)
55
+
56
+ # Add legend if show_legend is True
57
+ if show_legend:
58
+ ax.legend(facecolor=TEXT_COLOR if dark_mode else 'white',
59
+ edgecolor=TEXT_COLOR if dark_mode else 'white',
60
+ framealpha=0.6,
61
+ labelcolor=color,
62
+ fontsize=legend_fontsize,
63
+ loc='center left',
64
+ bbox_to_anchor=(1.01, 0.5))
65
+
66
+ # Format x-axis tick labels with the specified unit
67
+ if x_unit is not None:
68
+ formatter0 = EngFormatter(unit=x_unit)
69
+ ax.xaxis.set_major_formatter(formatter0)
70
+
71
+ # Format y-axis tick labels with the specified unit
72
+ if y_unit is not None:
73
+ formatter1 = EngFormatter(unit=y_unit)
74
+ ax.yaxis.set_major_formatter(formatter1)
75
+
76
+
77
+ def prep_label_for_radar(x):
78
+ label = x.lower().replace('count_', '').replace('_p90', '').replace(' P90', ''). \
79
+ replace('_per_30_tip', ' ').replace('runs', '').replace('opportunities_to_pass_to_', '').replace('_', ' '). \
80
+ strip().upper()
81
+ return label
82
+
83
+
84
+ def simplify_label(x):
85
+ label = x.lower().replace('carrera a ', '').replace('carrera de ', '').replace('carrera para ', '').replace('carrera',
86
+ '').replace(' por ','\n'). \
87
+ replace('course pour ', '').replace('course de ', '').replace('course', ''). \
88
+ replace('être à la', '').replace('dans la ', '').replace('dans le ', ''). \
89
+ replace('corsa ', '').\
90
+ replace('runs', ''). \
91
+ strip().upper()
92
+ return label