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
913import numpy as np
1418points = np .ones (3 ) # Draw 3 points for each line
1519text_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
2025def 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
2540def 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
3252fig , 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.
3556unfilled_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+
4159for 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):
5272fig , axes = plt .subplots (ncols = 2 )
5373for 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 )
5878fig .suptitle ('filled markers' , fontsize = 14 )
5979
6080plt .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