Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13f7a09

Browse files
committed
Add facecolor to axisline style
1 parent 5df9e3c commit 13f7a09

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

lib/mpl_toolkits/axisartist/axisline_style.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import numpy as np
44

5+
import matplotlib as mpl
56
from matplotlib.patches import _Style, FancyArrowPatch
6-
from matplotlib.transforms import IdentityTransform
77
from matplotlib.path import Path
8+
from matplotlib.transforms import IdentityTransform
89

910

1011
class _FancyAxislineStyle:
@@ -54,10 +55,10 @@ def set_path(self, path):
5455
def draw(self, renderer):
5556
"""
5657
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
58+
1) Transform the path to the display coordinate.
59+
2) Extend the path to make a room for arrow.
60+
3) Update the path of the FancyArrowPatch.
61+
4) Draw.
6162
"""
6263
path_in_disp = self._line_transform.transform_path(self._line_path)
6364
mutation_size = self.get_mutation_scale() # line_mutation_scale()
@@ -67,9 +68,15 @@ def draw(self, renderer):
6768
FancyArrowPatch.draw(self, renderer)
6869

6970
class FilledArrow(SimpleArrow):
70-
"""The artist class that will be returned for SimpleArrow style."""
71+
"""The artist class that will be returned for FilledArrow style."""
7172
_ARROW_STYLE = "-|>"
7273

74+
def __init__(self, axis_artist, line_path, transform,
75+
line_mutation_scale, facecolor):
76+
super().__init__(axis_artist, line_path, transform,
77+
line_mutation_scale)
78+
self.set_facecolor(facecolor)
79+
7380

7481
class AxislineStyle(_Style):
7582
"""
@@ -131,7 +138,6 @@ def __init__(self, size=1):
131138
super().__init__()
132139

133140
def new_line(self, axis_artist, transform):
134-
135141
linepath = Path([(0, 0), (0, 1)])
136142
axisline = self.ArrowAxisClass(axis_artist, linepath, transform,
137143
line_mutation_scale=self.size)
@@ -140,6 +146,30 @@ def new_line(self, axis_artist, transform):
140146
_style_list["->"] = SimpleArrow
141147

142148
class FilledArrow(SimpleArrow):
149+
def __init__(self, size=1, facecolor=None):
150+
"""
151+
Parameters
152+
----------
153+
size : float
154+
Size of the arrow as a fraction of the ticklabel size.
155+
facecolor : color, default: :rc:`axes.edgecolor`
156+
Fill color.
157+
.. versionadded:: 3.7
158+
"""
159+
160+
if facecolor is None:
161+
facecolor = mpl.rcParams['axes.edgecolor']
162+
self.size = size
163+
self._facecolor = facecolor
164+
super().__init__(size=size)
165+
166+
def new_line(self, axis_artist, transform):
167+
linepath = Path([(0, 0), (0, 1)])
168+
axisline = self.ArrowAxisClass(axis_artist, linepath, transform,
169+
line_mutation_scale=self.size,
170+
facecolor=self._facecolor)
171+
return axisline
172+
143173
ArrowAxisClass = _FancyAxislineStyle.FilledArrow
144174

145175
_style_list["-|>"] = FilledArrow

lib/mpl_toolkits/axisartist/tests/test_axislines.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from matplotlib.testing.decorators import image_comparison
44
from matplotlib.transforms import IdentityTransform
55

6-
from mpl_toolkits.axisartist.axislines import SubplotZero, Subplot
6+
from mpl_toolkits.axisartist.axislines import AxesZero, SubplotZero, Subplot
77
from mpl_toolkits.axisartist import Axes, SubplotHost
88

99

@@ -90,3 +90,30 @@ def test_ParasiteAxesAuxTrans():
9090
ax1.set_ylim((0, 5))
9191

9292
ax2.contour(xx, yy, data, colors='k')
93+
94+
95+
@image_comparison(['axisline_style.png'], remove_text=True, style='mpl20')
96+
def test_axisline_style():
97+
fig = plt.figure(figsize=(2, 2))
98+
ax = fig.add_subplot(axes_class=AxesZero)
99+
ax.axis["xzero"].set_axisline_style("-|>")
100+
ax.axis["xzero"].set_visible(True)
101+
ax.axis["yzero"].set_axisline_style("->")
102+
ax.axis["yzero"].set_visible(True)
103+
104+
for direction in ("left", "right", "bottom", "top"):
105+
ax.axis[direction].set_visible(False)
106+
107+
108+
@image_comparison(['axisline_style_size_color.png'], remove_text=True,
109+
style='mpl20')
110+
def test_axisline_style_size_color():
111+
fig = plt.figure(figsize=(2, 2))
112+
ax = fig.add_subplot(axes_class=AxesZero)
113+
ax.axis["xzero"].set_axisline_style("-|>", size=2.0, facecolor='r')
114+
ax.axis["xzero"].set_visible(True)
115+
ax.axis["yzero"].set_axisline_style("->, size=1.5")
116+
ax.axis["yzero"].set_visible(True)
117+
118+
for direction in ("left", "right", "bottom", "top"):
119+
ax.axis[direction].set_visible(False)

0 commit comments

Comments
 (0)