.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/pitch_plots/plot_convex_hull.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_convex_hull.py: =========== Convex Hull =========== This example shows how to plot a convex hull around a player's events. Thanks to `Devin Pleuler `_ for adding this to mplsoccer. .. GENERATED FROM PYTHON SOURCE LINES 10-18 .. code-block:: Python from mplsoccer import Pitch, Sbopen import matplotlib.pyplot as plt # read data parser = Sbopen() df, related, freeze, tactics = parser.event(7478) .. GENERATED FROM PYTHON SOURCE LINES 19-20 Filter passes by Jodie Taylor .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python df = df[(df.player_name == 'Jodie Taylor') & (df.type_name == 'Pass')].copy() .. GENERATED FROM PYTHON SOURCE LINES 23-24 Plotting .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. code-block:: Python pitch = Pitch() fig, ax = pitch.draw(figsize=(8, 6)) hull = pitch.convexhull(df.x, df.y) poly = pitch.polygon(hull, ax=ax, edgecolor='cornflowerblue', facecolor='cornflowerblue', alpha=0.3) scatter = pitch.scatter(df.x, df.y, ax=ax, edgecolor='black', facecolor='cornflowerblue') plt.show() # if you are not using a Jupyter notebook this is necessary to show the plot .. image-sg:: /gallery/pitch_plots/images/sphx_glr_plot_convex_hull_001.png :alt: plot convex hull :srcset: /gallery/pitch_plots/images/sphx_glr_plot_convex_hull_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.293 seconds) .. _sphx_glr_download_gallery_pitch_plots_plot_convex_hull.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_convex_hull.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_convex_hull.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_convex_hull.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_