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