diff --git a/galleries/examples/lines_bars_and_markers/scatter_custom_symbol.py b/galleries/examples/lines_bars_and_markers/scatter_custom_symbol.py deleted file mode 100644 index 3938747ddbc0..000000000000 --- a/galleries/examples/lines_bars_and_markers/scatter_custom_symbol.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -================================= -Scatter plots with custom symbols -================================= - -.. redirect-from:: /gallery/lines_bars_and_markers/scatter_symbol -.. redirect-from:: /gallery/lines_bars_and_markers/scatter_piecharts -""" - -# %% -# Using TeX symbols -# ----------------- -# An easy way to customize scatter symbols is passing a TeX symbol name -# enclosed in $-signs as a marker. Below we use ``marker=r'$\clubsuit$'``. - -import matplotlib.pyplot as plt -import numpy as np - -# Fixing random state for reproducibility -np.random.seed(19680801) - - -x = np.arange(0.0, 50.0, 2.0) -y = x ** 1.3 + np.random.rand(*x.shape) * 30.0 -sizes = np.random.rand(*x.shape) * 800 + 500 - -fig, ax = plt.subplots() -ax.scatter(x, y, sizes, c="green", alpha=0.5, marker=r'$\clubsuit$', - label="Luck") -ax.set_xlabel("Leprechauns") -ax.set_ylabel("Gold") -ax.legend() -plt.show() - -# %% -# Using a custom path -# ------------------- -# Alternatively, one can also pass a custom path of N vertices as a (N, 2) -# array of x, y values as *marker*. - -# unit area ellipse -rx, ry = 3., 1. -area = rx * ry * np.pi -theta = np.arange(0, 2 * np.pi + 0.01, 0.1) -verts = np.column_stack([rx / area * np.cos(theta), ry / area * np.sin(theta)]) - -x, y, s, c = np.random.rand(4, 30) -s *= 100 - -fig, ax = plt.subplots() -ax.scatter(x, y, s, c, marker=verts) - -plt.show() diff --git a/galleries/examples/lines_bars_and_markers/scatter_star_poly.py b/galleries/examples/lines_bars_and_markers/scatter_star_poly.py index 8f00ceccf4c1..d97408333455 100644 --- a/galleries/examples/lines_bars_and_markers/scatter_star_poly.py +++ b/galleries/examples/lines_bars_and_markers/scatter_star_poly.py @@ -5,7 +5,13 @@ Example with different ways to specify markers. -For a list of all markers see also the `matplotlib.markers` documentation. +See also the `matplotlib.markers` documentation for a list of all markers and +:doc:`/gallery/lines_bars_and_markers/marker_reference` for more information +on configuring markers. + +.. redirect-from:: /gallery/lines_bars_and_markers/scatter_custom_symbol +.. redirect-from:: /gallery/lines_bars_and_markers/scatter_symbol +.. redirect-from:: /gallery/lines_bars_and_markers/scatter_piecharts """ import matplotlib.pyplot as plt import numpy as np @@ -17,32 +23,31 @@ y = np.random.rand(10) z = np.sqrt(x**2 + y**2) -fig, axs = plt.subplots(2, 3, sharex=True, sharey=True) +fig, axs = plt.subplots(2, 3, sharex=True, sharey=True, layout="constrained") -# marker symbol +# Matplotlib marker symbol axs[0, 0].scatter(x, y, s=80, c=z, marker=">") axs[0, 0].set_title("marker='>'") -# marker from TeX -axs[0, 1].scatter(x, y, s=80, c=z, marker=r'$\alpha$') -axs[0, 1].set_title(r"marker=r'\$\alpha\$'") +# marker from TeX: passing a TeX symbol name enclosed in $-signs +axs[0, 1].scatter(x, y, s=80, c=z, marker=r"$\clubsuit$") +axs[0, 1].set_title(r"marker=r'\$\clubsuit\$'") -# marker from path +# marker from path: passing a custom path of N vertices as a (N, 2) array-like verts = [[-1, -1], [1, -1], [1, 1], [-1, -1]] axs[0, 2].scatter(x, y, s=80, c=z, marker=verts) axs[0, 2].set_title("marker=verts") -# regular polygon marker +# regular pentagon marker axs[1, 0].scatter(x, y, s=80, c=z, marker=(5, 0)) axs[1, 0].set_title("marker=(5, 0)") -# regular star marker +# regular 5-pointed star marker axs[1, 1].scatter(x, y, s=80, c=z, marker=(5, 1)) axs[1, 1].set_title("marker=(5, 1)") -# regular asterisk marker +# regular 5-pointed asterisk marker axs[1, 2].scatter(x, y, s=80, c=z, marker=(5, 2)) axs[1, 2].set_title("marker=(5, 2)") -plt.tight_layout() plt.show()