Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 71ec6c3

Browse filesBrowse files
committed
Add tests for Shadow class.
1 parent 428bda7 commit 71ec6c3
Copy full SHA for 71ec6c3

File tree

Expand file treeCollapse file tree

2 files changed

+38
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+38
-15
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,10 @@ def _update(self):
615615
if self.props is not None:
616616
self.update(self.props)
617617
else:
618-
r, g, b, a = colors.to_rgba(self.patch.get_facecolor())
619-
rho = 0.3
620-
r = rho * r
621-
g = rho * g
622-
b = rho * b
623-
624-
self.set_facecolor((r, g, b, 0.5))
625-
self.set_edgecolor((r, g, b, 0.5))
618+
self.set_facecolor(
619+
.3 * np.asarray(colors.to_rgb(self.patch.get_facecolor())))
620+
self.set_edgecolor(
621+
.3 * np.asarray(colors.to_rgb(self.patch.get_edgecolor())))
626622
self.set_alpha(0.5)
627623

628624
def _update_transform(self, renderer):

‎lib/matplotlib/tests/test_patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_patches.py
+34-7Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
from numpy.testing import assert_almost_equal, assert_array_equal
1010
import pytest
1111

12-
from matplotlib.patches import Polygon
13-
from matplotlib.patches import Rectangle
12+
from matplotlib.patches import Polygon, Rectangle
1413
from matplotlib.testing.decorators import image_comparison
1514
import matplotlib.pyplot as plt
16-
import matplotlib.patches as mpatches
17-
import matplotlib.collections as mcollections
18-
from matplotlib import path as mpath
19-
from matplotlib import transforms as mtransforms
20-
import matplotlib.style as mstyle
15+
from matplotlib import (
16+
collections as mcollections, colors as mcolors, patches as mpatches,
17+
path as mpath, style as mstyle, transforms as mtransforms)
2118

19+
from io import BytesIO
2220
import sys
2321
on_win = (sys.platform == 'win32')
2422

@@ -410,3 +408,32 @@ def test_contains_points():
410408
expected = path.contains_points(points, transform, radius)
411409
result = ell.contains_points(points)
412410
assert np.all(result == expected)
411+
412+
413+
def test_shadow():
414+
xy = np.array([.2, .3])
415+
dxy = np.array([.1, .2])
416+
# We need to work around the nonsensical (dpi-dependent) interpretation of
417+
# offsets by the Shadow class...
418+
with plt.rc_context({"savefig.dpi": "figure"}):
419+
# Test image.
420+
f1, a1 = plt.subplots()
421+
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
422+
shadow = mpatches.Shadow(rect, ox=dxy[0], oy=dxy[1])
423+
a1.add_patch(rect)
424+
a1.add_patch(shadow)
425+
b1 = BytesIO()
426+
f1.savefig(b1, format="raw")
427+
# Reference image.
428+
f2, a2 = plt.subplots()
429+
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
430+
shadow = mpatches.Rectangle(
431+
xy=xy + f2.dpi / 72 * dxy, width=.5, height=.5,
432+
fc=np.asarray(mcolors.to_rgb(rect.get_fc())) * .3,
433+
ec=np.asarray(mcolors.to_rgb(rect.get_ec())) * .3,
434+
alpha=.5)
435+
a2.add_patch(shadow)
436+
a2.add_patch(rect)
437+
b2 = BytesIO()
438+
f2.savefig(b2, format="raw")
439+
assert b1.getvalue() == b2.getvalue()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.