1
+ """
2
+ Provides classes to style the axis lines.
3
+ """
1
4
import math
2
5
3
6
import numpy as np
4
7
8
+ import matplotlib as mpl
5
9
from matplotlib .patches import _Style , FancyArrowPatch
6
- from matplotlib .transforms import IdentityTransform
7
10
from matplotlib .path import Path
11
+ from matplotlib .transforms import IdentityTransform
8
12
9
13
10
14
class _FancyAxislineStyle :
@@ -54,10 +58,10 @@ def set_path(self, path):
54
58
def draw (self , renderer ):
55
59
"""
56
60
Draw the axis line.
57
- 1) transform the path to the display coordinate.
58
- 2) extend the path to make a room for arrow
59
- 3) update the path of the FancyArrowPatch.
60
- 4) draw
61
+ 1) Transform the path to the display coordinate.
62
+ 2) Extend the path to make a room for arrow.
63
+ 3) Update the path of the FancyArrowPatch.
64
+ 4) Draw.
61
65
"""
62
66
path_in_disp = self ._line_transform .transform_path (self ._line_path )
63
67
mutation_size = self .get_mutation_scale () # line_mutation_scale()
@@ -67,9 +71,15 @@ def draw(self, renderer):
67
71
FancyArrowPatch .draw (self , renderer )
68
72
69
73
class FilledArrow (SimpleArrow ):
70
- """The artist class that will be returned for SimpleArrow style."""
74
+ """The artist class that will be returned for FilledArrow style."""
71
75
_ARROW_STYLE = "-|>"
72
76
77
+ def __init__ (self , axis_artist , line_path , transform ,
78
+ line_mutation_scale , facecolor ):
79
+ super ().__init__ (axis_artist , line_path , transform ,
80
+ line_mutation_scale )
81
+ self .set_facecolor (facecolor )
82
+
73
83
74
84
class AxislineStyle (_Style ):
75
85
"""
@@ -131,7 +141,6 @@ def __init__(self, size=1):
131
141
super ().__init__ ()
132
142
133
143
def new_line (self , axis_artist , transform ):
134
-
135
144
linepath = Path ([(0 , 0 ), (0 , 1 )])
136
145
axisline = self .ArrowAxisClass (axis_artist , linepath , transform ,
137
146
line_mutation_scale = self .size )
@@ -140,6 +149,35 @@ def new_line(self, axis_artist, transform):
140
149
_style_list ["->" ] = SimpleArrow
141
150
142
151
class FilledArrow (SimpleArrow ):
152
+ """
153
+ An arrow with a filled head.
154
+ """
155
+
143
156
ArrowAxisClass = _FancyAxislineStyle .FilledArrow
144
157
158
+ def __init__ (self , size = 1 , facecolor = None ):
159
+ """
160
+ Parameters
161
+ ----------
162
+ size : float
163
+ Size of the arrow as a fraction of the ticklabel size.
164
+ facecolor : color, default: :rc:`axes.edgecolor`
165
+ Fill color.
166
+
167
+ .. versionadded:: 3.7
168
+ """
169
+
170
+ if facecolor is None :
171
+ facecolor = mpl .rcParams ['axes.edgecolor' ]
172
+ self .size = size
173
+ self ._facecolor = facecolor
174
+ super ().__init__ (size = size )
175
+
176
+ def new_line (self , axis_artist , transform ):
177
+ linepath = Path ([(0 , 0 ), (0 , 1 )])
178
+ axisline = self .ArrowAxisClass (axis_artist , linepath , transform ,
179
+ line_mutation_scale = self .size ,
180
+ facecolor = self ._facecolor )
181
+ return axisline
182
+
145
183
_style_list ["-|>" ] = FilledArrow
0 commit comments