1
1
"""
2
- ================================
3
- Filled and unfilled-marker types
4
- ================================
2
+ ================
3
+ Marker Reference
4
+ ================
5
5
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.
7
11
"""
8
12
9
13
import numpy as np
14
18
points = np .ones (3 ) # Draw 3 points for each line
15
19
text_style = dict (horizontalalignment = 'right' , verticalalignment = 'center' ,
16
20
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" )
18
23
19
24
20
25
def format_axes (ax ):
21
26
ax .margins (0.2 )
22
27
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 )
23
38
24
39
25
40
def split_list (a_list ):
26
41
i_half = len (a_list ) // 2
27
42
return (a_list [:i_half ], a_list [i_half :])
28
43
44
+
29
45
###############################################################################
46
+ # Filled and unfilled-marker types
47
+ # ================================
48
+ #
49
+ #
30
50
# Plot all un-filled markers
31
51
32
52
fig , axes = plt .subplots (ncols = 2 )
53
+ fig .suptitle ('un-filled markers' , fontsize = 14 )
33
54
34
55
# Filter out filled markers and marker settings that do nothing.
35
56
unfilled_markers = [m for m , func in Line2D .markers .items ()
36
57
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
+
41
59
for ax , markers in zip (axes , split_list (unfilled_markers )):
42
60
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 )
44
62
ax .plot (y * points , marker = marker , ** marker_style )
45
63
format_axes (ax )
46
- fig .suptitle ('un-filled markers' , fontsize = 14 )
64
+
65
+ plt .show ()
66
+
47
67
48
68
49
69
###############################################################################
@@ -52,9 +72,36 @@ def split_list(a_list):
52
72
fig , axes = plt .subplots (ncols = 2 )
53
73
for ax , markers in zip (axes , split_list (Line2D .filled_markers )):
54
74
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 )
56
76
ax .plot (y * points , marker = marker , ** marker_style )
57
77
format_axes (ax )
58
78
fig .suptitle ('filled markers' , fontsize = 14 )
59
79
60
80
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 ()
0 commit comments