.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/tutorials/plot_wedges.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_tutorials_plot_wedges.py: =========== Plot wedges =========== This example shows how you can plot wedge and comet lines on normal axes. .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 12-15 Generate random data -------------------- First let's generate some random data .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python np.random.seed(42) x = np.random.uniform(0, 120, 10) y = np.random.uniform(0, 80, 10) x_end = np.random.uniform(0, 120, 10) y_end = np.random.uniform(0, 80, 10) .. GENERATED FROM PYTHON SOURCE LINES 22-26 Plot using wedges ----------------- This shows how to plot the lines using wedges. The code was donated by `Jon Ollington `_ .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: Python fig, ax = plt.subplots() ax.set_xlim(0, 120) ax.set_ylim(0, 80) for i in range(len(x)): ax.annotate('', xy=(x[i], y[i]), xytext=(x_end[i], y_end[i]), zorder=2, arrowprops=dict(arrowstyle="wedge,tail_width=1", linewidth=1, fc='red', ec='black', alpha=0.4), ) .. image-sg:: /gallery/tutorials/images/sphx_glr_plot_wedges_001.png :alt: plot wedges :srcset: /gallery/tutorials/images/sphx_glr_plot_wedges_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 36-39 Plot using lines ---------------- You can also use mplsoccer's lines function on normal axes. .. GENERATED FROM PYTHON SOURCE LINES 39-47 .. code-block:: Python from mplsoccer import lines fig, ax = plt.subplots() ax.set_xlim(0, 120) ax.set_ylim(0, 80) lc1 = lines(x, y, x_end, y_end, color='red', comet=True, transparent=True, alpha_start=0.1, alpha_end=0.4, ax=ax) .. image-sg:: /gallery/tutorials/images/sphx_glr_plot_wedges_002.png :alt: plot wedges :srcset: /gallery/tutorials/images/sphx_glr_plot_wedges_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-51 Plot using cmap --------------- You can also use plot using a color map using mplsoccer's lines function. .. GENERATED FROM PYTHON SOURCE LINES 51-59 .. code-block:: Python fig, ax = plt.subplots() ax.set_xlim(0, 120) ax.set_ylim(0, 80) lc2 = lines(x, y, x_end, y_end, cmap='viridis', comet=True, transparent=True, alpha_start=0.1, alpha_end=0.4, ax=ax) plt.show() # If you are using a Jupyter notebook you do not need this line .. image-sg:: /gallery/tutorials/images/sphx_glr_plot_wedges_003.png :alt: plot wedges :srcset: /gallery/tutorials/images/sphx_glr_plot_wedges_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.141 seconds) .. _sphx_glr_download_gallery_tutorials_plot_wedges.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_wedges.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_wedges.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_wedges.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_