11"""
22================
3- Marker Reference
3+ Marker reference
44================
55
6- Reference for filled-, unfilled- and custom marker types with Matplotlib.
6+ Matplotlib supports multiple categories of markers which are selected using
7+ the ``marker`` parameter of plot commands:
78
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.
9+ - `Unfilled markers`_
10+ - `Filled markers`_
11+ - `Markers created from TeX symbols`_
12+ - Custom markers can be created from paths. See
13+ :doc:`/gallery/shapes_and_collections/marker_path`.
14+
15+ For a list of all markers see also the `matplotlib.markers` documentation.
1116"""
1217
13- import numpy as np
1418import matplotlib .pyplot as plt
1519from matplotlib .lines import Line2D
1620
1721
18- points = np .ones (3 ) # Draw 3 points for each line
1922text_style = dict (horizontalalignment = 'right' , verticalalignment = 'center' ,
20- fontsize = 12 , fontdict = { 'family' : ' monospace'} )
23+ fontsize = 12 , fontfamily = ' monospace' )
2124marker_style = dict (linestyle = ':' , color = '0.8' , markersize = 10 ,
22- mfc = "C0 " , mec = "C0 " )
25+ markerfacecolor = "tab:blue " , markeredgecolor = "tab:blue " )
2326
2427
2528def format_axes (ax ):
@@ -30,17 +33,16 @@ def format_axes(ax):
3033
3134def split_list (a_list ):
3235 i_half = len (a_list ) // 2
33- return ( a_list [:i_half ], a_list [i_half :])
36+ return a_list [:i_half ], a_list [i_half :]
3437
3538
3639###############################################################################
37- # Filled and unfilled-marker types
38- # ================================
39- #
40- # Plot all un-filled markers
40+ # Unfilled markers
41+ # ================
42+ # Unfilled markers are single-colored.
4143
4244fig , axs = plt .subplots (ncols = 2 )
43- fig .suptitle ('un -filled markers' , fontsize = 14 )
45+ fig .suptitle ('Un -filled markers' , fontsize = 14 )
4446
4547# Filter out filled markers and marker settings that do nothing.
4648unfilled_markers = [m for m , func in Line2D .markers .items ()
@@ -49,29 +51,57 @@ def split_list(a_list):
4951for ax , markers in zip (axs , split_list (unfilled_markers )):
5052 for y , marker in enumerate (markers ):
5153 ax .text (- 0.5 , y , repr (marker ), ** text_style )
52- ax .plot (y * points , marker = marker , ** marker_style )
54+ ax .plot ([ y ] * 3 , marker = marker , ** marker_style )
5355 format_axes (ax )
5456
5557plt .show ()
5658
5759
5860###############################################################################
59- # Plot all filled markers.
61+ # Filled markers
62+ # ==============
6063
6164fig , axs = plt .subplots (ncols = 2 )
65+ fig .suptitle ('Filled markers' , fontsize = 14 )
6266for ax , markers in zip (axs , split_list (Line2D .filled_markers )):
6367 for y , marker in enumerate (markers ):
6468 ax .text (- 0.5 , y , repr (marker ), ** text_style )
65- ax .plot (y * points , marker = marker , ** marker_style )
69+ ax .plot ([ y ] * 3 , marker = marker , ** marker_style )
6670 format_axes (ax )
67- fig .suptitle ('filled markers' , fontsize = 14 )
71+
72+ plt .show ()
73+
74+ ###############################################################################
75+ # .. _marker_fill_styles:
76+ #
77+ # Marker fill styles
78+ # ------------------
79+ # The edge color and fill color of filled markers can be specified separately.
80+ # Additionally, the ``fillstyle`` can be configured to be unfilled, fully
81+ # filled, or half-filled in various directions. The half-filled styles use
82+ # ``markerfacecoloralt`` as secondary fill color.
83+
84+ fig , ax = plt .subplots ()
85+ fig .suptitle ('Marker fillstyle' , fontsize = 14 )
86+ fig .subplots_adjust (left = 0.4 )
87+
88+ filled_marker_style = dict (marker = 'o' , linestyle = ':' , markersize = 15 ,
89+ color = 'darkgrey' ,
90+ markerfacecolor = 'tab:blue' ,
91+ markerfacecoloralt = 'lightsteelblue' ,
92+ markeredgecolor = 'brown' )
93+
94+ for y , fill_style in enumerate (Line2D .fillStyles ):
95+ ax .text (- 0.5 , y , repr (fill_style ), ** text_style )
96+ ax .plot ([y ] * 3 , fillstyle = fill_style , ** filled_marker_style )
97+ format_axes (ax )
6898
6999plt .show ()
70100
71101
72102###############################################################################
73- # Custom Markers with MathText
74- # ============================
103+ # Markers created from TeX symbols
104+ # ================================
75105#
76106# Use :doc:`MathText </tutorials/text/mathtext>`, to use custom marker symbols,
77107# like e.g. ``"$\u266B$"``. For an overview over the STIX font symbols refer
@@ -80,17 +110,16 @@ def split_list(a_list):
80110
81111
82112fig , ax = plt .subplots ()
113+ fig .suptitle ('Mathtext markers' , fontsize = 14 )
83114fig .subplots_adjust (left = 0.4 )
84115
85- marker_style .update (mec = "None" , markersize = 15 )
116+ marker_style .update (markeredgecolor = "None" , markersize = 15 )
86117markers = ["$1$" , r"$\frac{1}{2}$" , "$f$" , "$\u266B $" , r"$\mathcal{A}$" ]
87118
88-
89119for y , marker in enumerate (markers ):
90120 # Escape dollars so that the text is written "as is", not as mathtext.
91121 ax .text (- 0.5 , y , repr (marker ).replace ("$" , r"\$" ), ** text_style )
92- ax .plot (y * points , marker = marker , ** marker_style )
122+ ax .plot ([ y ] * 3 , marker = marker , ** marker_style )
93123format_axes (ax )
94- fig .suptitle ('mathtext markers' , fontsize = 14 )
95124
96125plt .show ()
0 commit comments