Skip to content

Commit 354fa7d

Browse files
Doc: Markers update
1 parent 0865176 commit 354fa7d

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

examples/lines_bars_and_markers/marker_fillstyle_reference.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
=====================
55
66
Reference for marker fill-styles included with Matplotlib.
7+
8+
Also refer to the
9+
:doc:`/gallery/lines_bars_and_markers/marker_fillstyle_reference`
10+
and :doc:`/gallery/shapes_and_collections/marker_path` examples.
711
"""
812
import numpy as np
913
import matplotlib.pyplot as plt
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
"""
2-
================================
3-
Filled and unfilled-marker types
4-
================================
2+
================
3+
Marker Reference
4+
================
55
6-
Reference for filled- and unfilled-marker types included with Matplotlib.
6+
Reference for filled-, unfilled- and custom marker types with Matplotlib.
7+
8+
For a list of all markers see the `matplotlib.markers` documentation. Also
9+
refer to the :doc:`/gallery/lines_bars_and_markers/marker_fillstyle_reference`
10+
and :doc:`/gallery/shapes_and_collections/marker_path` examples.
711
"""
812

913
import numpy as np
@@ -14,36 +18,52 @@
1418
points = np.ones(3) # Draw 3 points for each line
1519
text_style = dict(horizontalalignment='right', verticalalignment='center',
1620
fontsize=12, fontdict={'family': 'monospace'})
17-
marker_style = dict(linestyle=':', color='cornflowerblue', markersize=10)
21+
marker_style = dict(linestyle=':', color='0.8', markersize=10,
22+
mfc="C0", mec="C0")
1823

1924

2025
def format_axes(ax):
2126
ax.margins(0.2)
2227
ax.set_axis_off()
28+
ax.invert_yaxis()
29+
30+
31+
def nice_repr(text):
32+
return repr(text).lstrip('u')
33+
34+
35+
def math_repr(text):
36+
tx = repr(text).lstrip('u').strip("'").strip("$")
37+
return "'\${}\$'".format(tx)
2338

2439

2540
def split_list(a_list):
2641
i_half = len(a_list) // 2
2742
return (a_list[:i_half], a_list[i_half:])
2843

44+
2945
###############################################################################
46+
# Filled and unfilled-marker types
47+
# ================================
48+
#
49+
#
3050
# Plot all un-filled markers
3151

3252
fig, axes = plt.subplots(ncols=2)
53+
fig.suptitle('un-filled markers', fontsize=14)
3354

3455
# Filter out filled markers and marker settings that do nothing.
3556
unfilled_markers = [m for m, func in Line2D.markers.items()
3657
if func != 'nothing' and m not in Line2D.filled_markers]
37-
# Reverse-sort for pretty. We use our own sort key which is essentially
38-
# a python3 compatible reimplementation of python2 sort.
39-
unfilled_markers = sorted(unfilled_markers,
40-
key=lambda x: (str(type(x)), str(x)))[::-1]
58+
4159
for ax, markers in zip(axes, split_list(unfilled_markers)):
4260
for y, marker in enumerate(markers):
43-
ax.text(-0.5, y, repr(marker), **text_style)
61+
ax.text(-0.5, y, nice_repr(marker), **text_style)
4462
ax.plot(y * points, marker=marker, **marker_style)
4563
format_axes(ax)
46-
fig.suptitle('un-filled markers', fontsize=14)
64+
65+
plt.show()
66+
4767

4868

4969
###############################################################################
@@ -52,9 +72,36 @@ def split_list(a_list):
5272
fig, axes = plt.subplots(ncols=2)
5373
for ax, markers in zip(axes, split_list(Line2D.filled_markers)):
5474
for y, marker in enumerate(markers):
55-
ax.text(-0.5, y, repr(marker), **text_style)
75+
ax.text(-0.5, y, nice_repr(marker), **text_style)
5676
ax.plot(y * points, marker=marker, **marker_style)
5777
format_axes(ax)
5878
fig.suptitle('filled markers', fontsize=14)
5979

6080
plt.show()
81+
82+
83+
###############################################################################
84+
# Custom Markers with MathText
85+
# ============================
86+
#
87+
#
88+
# Use :doc:`MathText </tutorials/text/mathtext>`, to use custom marker symbols,
89+
# like e.g. ``"$\u266B$"``. For an overview over the STIX font symbols refer to the
90+
# `STIX font table <http://www.stixfonts.org/allGlyphs.html>`_.
91+
# Also see the :doc:`/gallery/text_labels_and_annotations/stix_fonts_demo`.
92+
93+
94+
fig, ax = plt.subplots()
95+
fig.subplots_adjust(left=0.4)
96+
97+
marker_style.update(mec="None", markersize=15)
98+
markers = ["$1$", r"$\frac{1}{2}$", "$f$", "$\u266B$",
99+
r"$\mathcircled{m}$"]
100+
101+
102+
for y, marker in enumerate(markers):
103+
ax.text(-0.5, y, math_repr(marker), **text_style)
104+
ax.plot(y * points, marker=marker, **marker_style)
105+
format_axes(ax)
106+
107+
plt.show()

lib/matplotlib/markers.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
``"None"``, ``" "`` or ``""`` nothing
4949
``'$...$'`` |m37| Render the string using mathtext.
5050
E.g ``"$f$"`` for marker showing the
51-
letter ``f``.
51+
letter ``f``.
5252
``verts`` A list of (x, y) pairs used for Path
5353
vertices. The center of the marker is
5454
located at (0,0) and the size is
@@ -58,10 +58,10 @@
5858
``(numsides, style, angle)`` The marker can also be a tuple
5959
``(numsides, style, angle)``, which
6060
will create a custom, regular symbol.
61-
61+
6262
``numsides``:
6363
the number of sides
64-
64+
6565
``style``:
6666
the style of the regular symbol:
6767
@@ -76,7 +76,7 @@
7676
| | ``angle`` is ignored); |
7777
| | deprecated. |
7878
+---+-----------------------------+
79-
79+
8080
``angle``:
8181
the angle of rotation of the symbol
8282
============================== ====== =========================================
@@ -89,26 +89,26 @@
8989
referred to from other docs for the valid inputs from marker inputs and in
9090
those cases ``None`` still means 'default'.
9191
92-
Note that special symbols can be defined via the
92+
Note that special symbols can be defined via the
9393
:doc:`STIX math font </tutorials/text/mathtext>`,
9494
e.g. ``"$\u266B$"``. For an overview over the STIX font symbols refer to the
9595
`STIX font table <http://www.stixfonts.org/allGlyphs.html>`_.
9696
Also see the :doc:`/gallery/text_labels_and_annotations/stix_fonts_demo`.
9797
9898
Integer numbers from ``0`` to ``11`` create lines and triangles. Those are
99-
equally accessible via capitalied variables, like ``CARETDOWNBASE``.
99+
equally accessible via capitalized variables, like ``CARETDOWNBASE``.
100100
Hence the following are equivalent::
101101
102102
plt.plot([1,2,3], marker=11)
103-
plt.plot([1,2,3], marker=marker=matplotlib.markers.CARETDOWNBASE)
104-
103+
plt.plot([1,2,3], marker=matplotlib.markers.CARETDOWNBASE)
104+
105105
106106
Examples showing the use of markers:
107107
108108
* :doc:`/gallery/lines_bars_and_markers/marker_reference`
109109
* :doc:`/gallery/lines_bars_and_markers/marker_fillstyle_reference`
110110
* :doc:`/gallery/shapes_and_collections/marker_path`
111-
111+
112112
113113
.. |m00| image:: /_static/markers/m00.png
114114
.. |m01| image:: /_static/markers/m01.png

0 commit comments

Comments
 (0)