1
1
"""
2
- Types that would not normally have their own class are documented here.
2
+ Concepts used by the matplotlib API that do not yet have a dedicated class.
3
+
4
+ Matplotlib often uses simple data types like strings or tuples to define a
5
+ concept; e.g. the line capstyle can be specified as one of 'butt', 'round',
6
+ or 'projecting'. The classes in this module are used internally and document
7
+ these concepts formally.
8
+
9
+ As an end-user you will not use these classes directly, but only the values
10
+ they define.
3
11
"""
4
12
5
13
from enum import Enum ,auto
@@ -48,25 +56,29 @@ class JoinStyle(str, _AutoStringNameEnum):
48
56
49
57
**Supported values:**
50
58
51
- - *miter*: the "arrow-tip" style. Each boundary of the filled-in area
52
- will extend in a straight line parallel to the tangent vector of the
53
- centerline at the point it meets the corner, until they meet in a
54
- sharp point.
55
- - *round*: stokes every point within a radius of ``linewidth/2`` of the
56
- center lines.
57
- - *bevel*: the "squared-off" style. It can be thought of as a rounded
58
- corner where the "circular" part of the corner has been cut off.
59
+ .. rst-class:: value-list
60
+
61
+ 'miter'
62
+ the "arrow-tip" style. Each boundary of the filled-in area will
63
+ extend in a straight line parallel to the tangent vector of the
64
+ centerline at the point it meets the corner, until they meet in a
65
+ sharp point.
66
+ 'round'
67
+ stokes every point within a radius of ``linewidth/2`` of the center
68
+ lines.
69
+ 'bevel'
70
+ the "squared-off" style. It can be thought of as a rounded corner
71
+ where the "circular" part of the corner has been cut off.
59
72
60
73
.. note::
61
74
62
- The *miter* option can be controlled further by specifying a "miter
63
- limit", which specifies how long a miter tip can get before it is
64
- automatically "bevel"ed off. Matplotlib does not currently expose a
65
- ``miterlimit`` parameter to the user, and most backends simply use the
66
- upstream default value. For example, the PDF backend assumes the
67
- default value of 10 specified by the PDF standard, while the SVG
68
- backend does not even specify the miter limit, resulting in a default
69
- value of 4 per the SVG specification.
75
+ Very long miter tips are cut off (to form a *bevel*) after a
76
+ backend-dependent limit called the "miter limit", which specifies the
77
+ maximum allowed ratio of miter length to line width. For example, the
78
+ PDF backend uses the default value of 10 specified by the PDF standard,
79
+ while the SVG backend does not even specify the miter limit, resulting
80
+ in a default value of 4 per the SVG specification. Matplotlib does not
81
+ currently allow the user to adjust this parameter.
70
82
71
83
A more detailed description of the effect of a miter limit can be found
72
84
in the `Mozilla Developer Docs
@@ -102,7 +114,7 @@ def plot_angle(ax, x, y, angle, style):
102
114
ax .plot (xx ,yy ,lw = 1 ,color = 'black' )
103
115
ax .plot (xx [1 ],yy [1 ],'o' ,color = 'tab:red' ,markersize = 3 )
104
116
105
- fig ,ax = plt .subplots (figsize = (8 , 6 ) )
117
+ fig ,ax = plt .subplots (figsize = (5 , 4 ), constrained_layout = True )
106
118
ax .set_title ('Join style' )
107
119
for x ,style in enumerate (['miter' ,'round' ,'bevel' ]):
108
120
ax .text (x ,5 ,style )
@@ -114,6 +126,8 @@ def plot_angle(ax, x, y, angle, style):
114
126
ax .set_ylim (- .5 ,5.5 )
115
127
ax .set_axis_off ()
116
128
fig .show ()
129
+
130
+
117
131
JoinStyle .input_description = "{" \
118
132
+ ", " .join ([f"'{ js .name } '" for js in JoinStyle ]) \
119
133
+ "}"
@@ -133,11 +147,16 @@ class CapStyle(str, _AutoStringNameEnum):
133
147
134
148
**Supported values:**
135
149
136
- - *butt*: the line is squared off at its endpoint.
137
- - *projecting*: the line is squared off as in *butt*, but the filled in
138
- area extends beyond the endpoint a distance of ``linewidth/2``.
139
- - *round*: like *butt*, but a semicircular cap is added to the end of
140
- the line, of radius ``linewidth/2``.
150
+ .. rst-class:: value-list
151
+
152
+ 'butt'
153
+ the line is squared off at its endpoint.
154
+ 'projecting'
155
+ the line is squared off as in *butt*, but the filled in area
156
+ extends beyond the endpoint a distance of ``linewidth/2``.
157
+ 'round'
158
+ like *butt*, but a semicircular cap is added to the end of the
159
+ line, of radius ``linewidth/2``.
141
160
142
161
.. plot::
143
162
:alt: Demo of possible CapStyle's
@@ -159,21 +178,24 @@ def demo():
159
178
"""Demonstrate how each CapStyle looks for a thick line segment."""
160
179
import matplotlib .pyplot as plt
161
180
162
- fig ,ax = plt .subplots (figsize = (8 ,2 ))
181
+ fig = plt .figure (figsize = (4 ,1.2 ))
182
+ ax = fig .add_axes ([0 ,0 ,1 ,0.8 ])
163
183
ax .set_title ('Cap style' )
164
184
165
185
for x ,style in enumerate (['butt' ,'round' ,'projecting' ]):
166
- ax .text (x + 0.25 ,1 ,style ,ha = 'center' )
186
+ ax .text (x + 0.25 ,0.85 ,style ,ha = 'center' )
167
187
xx = [x ,x + 0.5 ]
168
188
yy = [0 ,0 ]
169
189
ax .plot (xx ,yy ,lw = 12 ,color = 'tab:blue' ,solid_capstyle = style )
170
190
ax .plot (xx ,yy ,lw = 1 ,color = 'black' )
171
191
ax .plot (xx ,yy ,'o' ,color = 'tab:red' ,markersize = 3 )
172
- ax .text (2.25 ,0.7 ,'(default)' ,ha = 'center' )
192
+ ax .text (2.25 ,0.55 ,'(default)' ,ha = 'center' )
173
193
174
194
ax .set_ylim (- .5 ,1.5 )
175
195
ax .set_axis_off ()
176
196
fig .show ()
197
+
198
+
177
199
CapStyle .input_description = "{" \
178
200
+ ", " .join ([f"'{ cs .name } '" for cs in CapStyle ]) \
179
201
+ "}"