.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/pitch_plots/plot_delaunay.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_pitch_plots_plot_delaunay.py: ====================================== Plots Delaunay Tessellation of Players ====================================== This example shows how to plot the delaunay tesellation for a shot freeze frame Added by `Matthew Williamson `_ .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import pandas as pd from mplsoccer import VerticalPitch, Sbopen # get event and freeze frame data for game 7478 parser = Sbopen() df_event, related, df_freeze, tactics = parser.event(7478) .. GENERATED FROM PYTHON SOURCE LINES 23-24 Subset a shot .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. code-block:: Python SHOT_ID = '974211ad-df10-4fac-a61c-6329e0c32af8' df_freeze_frame = df_freeze[df_freeze.id == SHOT_ID].copy() df_shot_event = df_event[df_event.id == SHOT_ID].dropna(axis=1, how='all').copy() .. GENERATED FROM PYTHON SOURCE LINES 30-31 Location dataset .. GENERATED FROM PYTHON SOURCE LINES 31-38 .. code-block:: Python df = pd.concat([df_shot_event[['x', 'y']], df_freeze_frame[['x', 'y']]]) x = df.x.values y = df.y.values teams = np.concatenate([[True], df_freeze_frame.teammate.values]) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Plotting .. GENERATED FROM PYTHON SOURCE LINES 40-57 .. code-block:: Python # draw plot pitch = VerticalPitch(half=True, pitch_color='w', line_color='k') fig, ax = pitch.draw(figsize=(8, 6.2)) # Get positions of Team B - which we'll use for plotting team_b_x = x[~teams] team_b_y = y[~teams] # Plot triangles t1 = pitch.triplot(team_b_x, team_b_y, ax=ax, color='dimgrey', linewidth=2) # Plot players sc1 = pitch.scatter(x[teams], y[teams], ax=ax, c='#c34c45', s=150, zorder=10) sc2 = pitch.scatter(team_b_x, team_b_y, ax=ax, c='#6f63c5', s=150, zorder=10) plt.show() # If you are using a Jupyter notebook you do not need this line .. image-sg:: /gallery/pitch_plots/images/sphx_glr_plot_delaunay_001.png :alt: plot delaunay :srcset: /gallery/pitch_plots/images/sphx_glr_plot_delaunay_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.287 seconds) .. _sphx_glr_download_gallery_pitch_plots_plot_delaunay.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_delaunay.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_delaunay.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_delaunay.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_