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

Skip to content

Commit 3d31865

Browse files
committed
Various path effects related updates.
1 parent d5f9876 commit 3d31865

File tree

7 files changed

+197
-203
lines changed

7 files changed

+197
-203
lines changed

doc/api/api_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ original location:
5454
'open-close-high-low' order of quotes, and what the module used and the later
5555
is 'open-high-low-close' order of quotes, which is the standard in finance.
5656

57+
* For consistency the ``face_alpha`` keyword to
58+
:class:`matplotlib.patheffects.SimplePatchShadow`'s has been deprecated.
59+
Use alpha instead.
60+
5761
* The artist used to draw the outline of a `colorbar` has been changed
5862
from a `matplotlib.lines.Line2D` to `matplotlib.patches.Polygon`,
5963
thus `colorbar.ColorbarBase.outline` is now a

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def _iter_collection(self, gc, master_transform, all_transforms,
392392
if not (np.isfinite(xo) and np.isfinite(yo)):
393393
continue
394394
if Nfacecolors:
395-
rgbFace = facecolors[i % Nfacecolors]
395+
rgbFace = tuple(facecolors[i % Nfacecolors])
396396
if Nedgecolors:
397397
if Nlinewidths:
398398
gc0.set_linewidth(linewidths[i % Nlinewidths])

lib/matplotlib/backends/backend_mixed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
unicode_literals)
33

44
import six
5+
56
from matplotlib._image import frombuffer
67
from matplotlib.backends.backend_agg import RendererAgg
78
from matplotlib.tight_bbox import process_figure_for_rasterizing
89

10+
911
class MixedModeRenderer(object):
1012
"""
1113
A helper class to implement a renderer that switches between
@@ -103,7 +105,6 @@ def start_rasterizing(self):
103105
self._set_current_renderer(self._raster_renderer)
104106
self._rasterizing += 1
105107

106-
107108
def stop_rasterizing(self):
108109
"""
109110
Exit "raster" mode. All of the drawing that was done since

lib/matplotlib/patches.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,33 +1818,45 @@ def __init__(self, pad=0.3):
18181818
super(BoxStyle.Square, self).__init__()
18191819

18201820
def transmute(self, x0, y0, width, height, mutation_size):
1821-
1822-
# padding
18231821
pad = mutation_size * self.pad
18241822

18251823
# width and height with padding added.
1826-
width, height = width + 2. * pad, \
1827-
height + 2. * pad,
1824+
width, height = width + 2*pad, height + 2*pad
18281825

18291826
# boundary of the padded box
18301827
x0, y0 = x0 - pad, y0 - pad,
18311828
x1, y1 = x0 + width, y0 + height
18321829

1833-
cp = [(x0, y0), (x1, y0), (x1, y1), (x0, y1),
1834-
(x0, y0), (x0, y0)]
1830+
vertices = [(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)]
1831+
codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
1832+
return Path(vertices, codes)
18351833

1836-
com = [Path.MOVETO,
1837-
Path.LINETO,
1838-
Path.LINETO,
1839-
Path.LINETO,
1840-
Path.LINETO,
1841-
Path.CLOSEPOLY]
1834+
_style_list["square"] = Square
18421835

1843-
path = Path(cp, com)
18441836

1845-
return path
1837+
class Circle(_Base):
1838+
"""A simple circle box."""
1839+
def __init__(self, pad=0.3):
1840+
"""
1841+
Parameters
1842+
----------
1843+
pad : float
1844+
The amount of padding around the original box.
1845+
"""
1846+
self.pad = pad
1847+
super(BoxStyle.Circle, self).__init__()
1848+
1849+
def transmute(self, x0, y0, width, height, mutation_size):
1850+
pad = mutation_size * self.pad
1851+
width, height = width + 2* pad, height + 2* pad
1852+
1853+
# boundary of the padded box
1854+
x0, y0 = x0 - pad, y0 - pad,
1855+
return Path.circle((x0 + width/2., y0 + height/2.),
1856+
(max([width, height]) / 2.))
1857+
1858+
_style_list["circle"] = Circle
18461859

1847-
_style_list["square"] = Square
18481860

18491861
class LArrow(_Base):
18501862
"""
@@ -2130,16 +2142,13 @@ def transmute(self, x0, y0, width, height, mutation_size):
21302142

21312143
saw_vertices = self._get_sawtooth_vertices(x0, y0, width,
21322144
height, mutation_size)
2133-
path = Path(saw_vertices)
2145+
path = Path(saw_vertices, closed=True)
21342146
return path
21352147

21362148
_style_list["sawtooth"] = Sawtooth
21372149

21382150
class Roundtooth(Sawtooth):
2139-
"""
2140-
A roundtooth(?) box.
2141-
"""
2142-
2151+
"""A rounded tooth box."""
21432152
def __init__(self, pad=0.3, tooth_size=None):
21442153
"""
21452154
*pad*
@@ -2151,16 +2160,14 @@ def __init__(self, pad=0.3, tooth_size=None):
21512160
super(BoxStyle.Roundtooth, self).__init__(pad, tooth_size)
21522161

21532162
def transmute(self, x0, y0, width, height, mutation_size):
2154-
21552163
saw_vertices = self._get_sawtooth_vertices(x0, y0,
21562164
width, height,
21572165
mutation_size)
2158-
2159-
cp = [Path.MOVETO] + ([Path.CURVE3, Path.CURVE3]
2160-
* ((len(saw_vertices) - 1) // 2))
2161-
path = Path(saw_vertices, cp)
2162-
2163-
return path
2166+
saw_vertices = np.concatenate([np.array(saw_vertices), [saw_vertices[0]]], axis=0)
2167+
cp = ([Path.MOVETO] +
2168+
[Path.CURVE3, Path.CURVE3] * ((len(saw_vertices) - 1) // 2) +
2169+
[Path.CLOSEPOLY])
2170+
return Path(saw_vertices, cp)
21642171

21652172
_style_list["roundtooth"] = Roundtooth
21662173

lib/matplotlib/path.py

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -679,63 +679,73 @@ def unit_regular_asterisk(cls, numVertices):
679679
@classmethod
680680
def unit_circle(cls):
681681
"""
682-
Return a :class:`Path` of the unit circle.
682+
Return the readonly :class:`Path` of the unit circle.
683+
684+
For most cases, :func:`Path.circle` will be what you want.
685+
686+
"""
687+
if cls._unit_circle is None:
688+
cls._unit_circle = cls.circle(center=(0, 0), radius=1,
689+
readonly=True)
690+
return cls._unit_circle
691+
692+
@classmethod
693+
def circle(cls, center=(0, 0), radius=1., readonly=False):
694+
"""
695+
Return a Path representing a circle of a given radius an center
696+
683697
The circle is approximated using cubic Bezier curves. This
684698
uses 8 splines around the circle using the approach presented
685699
here:
686700
687701
Lancaster, Don. `Approximating a Circle or an Ellipse Using Four
688702
Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_.
689703
"""
690-
if cls._unit_circle is None:
691-
MAGIC = 0.2652031
692-
SQRTHALF = np.sqrt(0.5)
693-
MAGIC45 = np.sqrt((MAGIC*MAGIC) / 2.0)
704+
MAGIC = 0.2652031
705+
SQRTHALF = np.sqrt(0.5)
706+
MAGIC45 = np.sqrt((MAGIC*MAGIC) / 2.0)
694707

695-
vertices = np.array(
696-
[[0.0, -1.0],
708+
vertices = np.array(
709+
[[0.0, -1.0],
697710

698-
[MAGIC, -1.0],
699-
[SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45],
700-
[SQRTHALF, -SQRTHALF],
701-
702-
[SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45],
703-
[1.0, -MAGIC],
704-
[1.0, 0.0],
711+
[MAGIC, -1.0],
712+
[SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45],
713+
[SQRTHALF, -SQRTHALF],
705714

706-
[1.0, MAGIC],
707-
[SQRTHALF+MAGIC45, SQRTHALF-MAGIC45],
708-
[SQRTHALF, SQRTHALF],
715+
[SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45],
716+
[1.0, -MAGIC],
717+
[1.0, 0.0],
709718

710-
[SQRTHALF-MAGIC45, SQRTHALF+MAGIC45],
711-
[MAGIC, 1.0],
712-
[0.0, 1.0],
719+
[1.0, MAGIC],
720+
[SQRTHALF+MAGIC45, SQRTHALF-MAGIC45],
721+
[SQRTHALF, SQRTHALF],
713722

714-
[-MAGIC, 1.0],
715-
[-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45],
716-
[-SQRTHALF, SQRTHALF],
723+
[SQRTHALF-MAGIC45, SQRTHALF+MAGIC45],
724+
[MAGIC, 1.0],
725+
[0.0, 1.0],
717726

718-
[-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45],
719-
[-1.0, MAGIC],
720-
[-1.0, 0.0],
727+
[-MAGIC, 1.0],
728+
[-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45],
729+
[-SQRTHALF, SQRTHALF],
721730

722-
[-1.0, -MAGIC],
723-
[-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45],
724-
[-SQRTHALF, -SQRTHALF],
731+
[-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45],
732+
[-1.0, MAGIC],
733+
[-1.0, 0.0],
725734

726-
[-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45],
727-
[-MAGIC, -1.0],
728-
[0.0, -1.0],
735+
[-1.0, -MAGIC],
736+
[-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45],
737+
[-SQRTHALF, -SQRTHALF],
729738

730-
[0.0, -1.0]],
731-
np.float_)
739+
[-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45],
740+
[-MAGIC, -1.0],
741+
[0.0, -1.0],
732742

733-
codes = cls.CURVE4 * np.ones(26)
734-
codes[0] = cls.MOVETO
735-
codes[-1] = cls.CLOSEPOLY
743+
[0.0, -1.0]], np.float_)
736744

737-
cls._unit_circle = cls(vertices, codes, readonly=True)
738-
return cls._unit_circle
745+
codes = cls.CURVE4 * np.ones(26)
746+
codes[0] = cls.MOVETO
747+
codes[-1] = cls.CLOSEPOLY
748+
return Path(vertices * radius + center, codes, readonly=readonly)
739749

740750
_unit_circle_righthalf = None
741751

0 commit comments

Comments
 (0)