1
1
"""
2
2
================
3
- Marker Reference
3
+ Marker reference
4
4
================
5
5
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:
7
8
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.
11
16
"""
12
17
13
- import numpy as np
14
18
import matplotlib .pyplot as plt
15
19
from matplotlib .lines import Line2D
16
20
17
21
18
- points = np .ones (3 ) # Draw 3 points for each line
19
22
text_style = dict (horizontalalignment = 'right' , verticalalignment = 'center' ,
20
- fontsize = 12 , fontdict = { 'family' : ' monospace'} )
23
+ fontsize = 12 , fontfamily = ' monospace' )
21
24
marker_style = dict (linestyle = ':' , color = '0.8' , markersize = 10 ,
22
- mfc = "C0 " , mec = "C0 " )
25
+ mfc = "tab:blue " , mec = "tab:blue " )
23
26
24
27
25
28
def format_axes (ax ):
@@ -30,17 +33,16 @@ def format_axes(ax):
30
33
31
34
def split_list (a_list ):
32
35
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 :]
34
37
35
38
36
39
###############################################################################
37
- # Filled and unfilled-marker types
38
- # ================================
39
- #
40
- # Plot all un-filled markers
40
+ # Unfilled markers
41
+ # ================
42
+ # Unfilled markers are single-colored.
41
43
42
44
fig , axs = plt .subplots (ncols = 2 )
43
- fig .suptitle ('un -filled markers' , fontsize = 14 )
45
+ fig .suptitle ('Un -filled markers' , fontsize = 14 )
44
46
45
47
# Filter out filled markers and marker settings that do nothing.
46
48
unfilled_markers = [m for m , func in Line2D .markers .items ()
@@ -49,29 +51,57 @@ def split_list(a_list):
49
51
for ax , markers in zip (axs , split_list (unfilled_markers )):
50
52
for y , marker in enumerate (markers ):
51
53
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 )
53
55
format_axes (ax )
54
56
55
57
plt .show ()
56
58
57
59
58
60
###############################################################################
59
- # Plot all filled markers.
61
+ # Filled markers
62
+ # ==============
60
63
61
64
fig , axs = plt .subplots (ncols = 2 )
65
+ fig .suptitle ('Filled markers' , fontsize = 14 )
62
66
for ax , markers in zip (axs , split_list (Line2D .filled_markers )):
63
67
for y , marker in enumerate (markers ):
64
68
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 )
66
70
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 )
68
98
69
99
plt .show ()
70
100
71
101
72
102
###############################################################################
73
- # Custom Markers with MathText
74
- # ============================
103
+ # Markers created from TeX symbols
104
+ # ================================
75
105
#
76
106
# Use :doc:`MathText </tutorials/text/mathtext>`, to use custom marker symbols,
77
107
# like e.g. ``"$\u266B$"``. For an overview over the STIX font symbols refer
@@ -80,17 +110,16 @@ def split_list(a_list):
80
110
81
111
82
112
fig , ax = plt .subplots ()
113
+ fig .suptitle ('Mathtext markers' , fontsize = 14 )
83
114
fig .subplots_adjust (left = 0.4 )
84
115
85
116
marker_style .update (mec = "None" , markersize = 15 )
86
117
markers = ["$1$" , r"$\frac{1}{2}$" , "$f$" , "$\u266B $" , r"$\mathcal{A}$" ]
87
118
88
-
89
119
for y , marker in enumerate (markers ):
90
120
# Escape dollars so that the text is written "as is", not as mathtext.
91
121
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 )
93
123
format_axes (ax )
94
- fig .suptitle ('mathtext markers' , fontsize = 14 )
95
124
96
125
plt .show ()
0 commit comments