8000 Add tests for Shadow class. · matplotlib/matplotlib@f4d158d · GitHub
[go: up one dir, main page]

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 f4d158d

Browse files
committed
Add tests for Shadow class.
1 parent 89846f1 commit f4d158d

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

lib/matplotlib/patches.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,9 @@ def _update(self):
588588
if self.props is not None:
589589
self.update(self.props)
590590
else:
591-
r, g, b, a = colors.to_rgba(self.patch.get_facecolor())
592-
rho = 0.3
593-
r = rho * r
594-
g = rho * g
595-
b = rho * b
596-
597-
self.set_facecolor((r, g, b, 0.5))
598-
self.set_edgecolor((r, g, b, 0.5))
591+
color = .3 * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
592+
self.set_facecolor(color)
593+
self.set_edgecolor(color)
599594
self.set_alpha(0.5)
600595

601596
def _update_transform(self, renderer):

lib/matplotlib/tests/test_patches.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
from numpy.testing import assert_almost_equal, assert_array_equal
66
import pytest
77

8-
from matplotlib.patches import Polygon
9-
from< 10000 /span> matplotlib.patches import Rectangle
10-
from matplotlib.testing.decorators import image_comparison
8+
from matplotlib.patches import Polygon, Rectangle
9+
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1110
import matplotlib.pyplot as plt
12-
import matplotlib.patches as mpatches
13-
import matplotlib.collections as mcollections
14-
from matplotlib import path as mpath
15-
from matplotlib import transforms as mtransforms
16-
import matplotlib.style as mstyle
11+
from matplotlib import (
12+
collections as mcollections, colors as mcolors, patches as mpatches,
13+
path as mpath, style as mstyle, transforms as mtransforms)
1714

1815
import sys
1916
on_win = (sys.platform == 'win32')
@@ -443,3 +440,29 @@ def test_contains_points():
443440
expected = path.contains_points(points, transform, radius)
444441
result = ell.contains_points(points)
445442
assert np.all(result == expected)
443+
444+
445+
# Currently fails with pdf/svg, probably because some parts assume a dpi of 72.
446+
@check_figures_equal(extensions=["png"])
447+
def test_shadow(fig_test, fig_ref):
448+
xy = np.array([.2, .3])
449+
dxy = np.array([.1, .2])
450+
# We need to work around the nonsensical (dpi-dependent) interpretation of
451+
# offsets by the Shadow class...
452+
plt.rcParams["savefig.dpi"] = "figure"
453+
# Test image.
454+
a1 = fig_test.subplots()
455+
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
456+
shadow = mpatches.Shadow(rect, ox=dxy[0], oy=dxy[1])
457+
a1.add_patch(rect)
458+
a1.add_patch(shadow)
459+
# Reference image.
460+
a2 = fig_ref.subplots()
461+
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
462+
shadow = mpatches.Rectangle(
463+
xy=xy + fig_ref.dpi / 72 * dxy, width=.5, height=.5,
464+
fc=np.asarray(mcolors.to_rgb(rect.get_fc())) * .3,
465+
ec=np.asarray(mcolors.to_rgb(rect.get_fc())) * .3,
466+
alpha=.5)
467+
a2.add_patch(shadow)
468+
a2.add_patch(rect)

0 commit comments

Comments
 (0)
0