|
9 | 9 | - `Unfilled markers`_
|
10 | 10 | - `Filled markers`_
|
11 | 11 | - `Markers created from TeX symbols`_
|
12 |
| -- Custom markers can be created from paths. See |
13 |
| - :doc:`/gallery/shapes_and_collections/marker_path`. |
| 12 | +- `Markers created from Paths`_ |
14 | 13 |
|
15 | 14 | For a list of all markers see also the `matplotlib.markers` documentation.
|
16 | 15 |
|
17 | 16 | For example usages see
|
18 | 17 | :doc:`/gallery/lines_bars_and_markers/scatter_star_poly`.
|
| 18 | +
|
| 19 | +.. redirect-from:: /gallery/shapes_and_collections/marker_path |
19 | 20 | """
|
20 | 21 |
|
21 | 22 | import matplotlib.pyplot as plt
|
@@ -126,3 +127,35 @@ def split_list(a_list):
|
126 | 127 | format_axes(ax)
|
127 | 128 |
|
128 | 129 | plt.show()
|
| 130 | + |
| 131 | + |
| 132 | +############################################################################### |
| 133 | +# Markers created from Paths |
| 134 | +# ========================== |
| 135 | +# |
| 136 | +# Any `~.path.Path` can be used as a marker. The following example shows two |
| 137 | +# simple paths *star* and *circle*, and a more elaborate path of a circle with |
| 138 | +# a cut-out star. |
| 139 | + |
| 140 | +import matplotlib.path as mpath |
| 141 | +import numpy as np |
| 142 | + |
| 143 | +star = mpath.Path.unit_regular_star(6) |
| 144 | +circle = mpath.Path.unit_circle() |
| 145 | +# concatenate the circle with an internal cutout of the star |
| 146 | +cut_star = mpath.Path( |
| 147 | + vertices=np.concatenate([circle.vertices, star.vertices[::-1, ...]]), |
| 148 | + codes=np.concatenate([circle.codes, star.codes])) |
| 149 | + |
| 150 | +fig, ax = plt.subplots() |
| 151 | +fig.suptitle('Path markers', fontsize=14) |
| 152 | +fig.subplots_adjust(left=0.4) |
| 153 | + |
| 154 | +markers = {'star': star, 'circle': circle, 'cut_star': cut_star} |
| 155 | + |
| 156 | +for y, (name, marker) in enumerate(markers.items()): |
| 157 | + ax.text(-0.5, y, name, **text_style) |
| 158 | + ax.plot([y] * 3, marker=marker, **marker_style) |
| 159 | +format_axes(ax) |
| 160 | + |
| 161 | +plt.show() |
0 commit comments