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 25f96fb

Browse filesBrowse files
committed
Add tests for Shadow class.
1 parent 205c15c commit 25f96fb
Copy full SHA for 25f96fb

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
@@ -631,14 +631,10 @@ def _update(self):
631631
if self.props is not None:
632632
self.update(self.props)
633633
else:
634-
r, g, b, a = colors.to_rgba(self.patch.get_facecolor())
635-
rho = 0.3
636-
r = rho * r
637-
g = rho * g
638-
b = rho * b
639-
640-
self.set_facecolor((r, g, b, 0.5))
641-
self.set_edgecolor((r, g, b, 0.5))
634+
self.set_facecolor(
635+
.3 * np.asarray(colors.to_rgb(self.patch.get_facecolor())))
636+
self.set_edgecolor(
637+
.3 * np.asarray(colors.to_rgb(self.patch.get_edgecolor())))
642638
self.set_alpha(0.5)
643639

644640
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
@@ -10,16 +10,14 @@
1010
from numpy.testing import assert_almost_equal, assert_array_equal
1111
import pytest
1212

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

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

@@ -362,3 +360,32 @@ def test_connection_patch():
362360
axesA=ax2, axesB=ax1,
363361
arrowstyle="->")
364362
ax2.add_artist(con)
363+
364+
365+
def test_shadow():
366+
xy = np.array([.24, .26])
367+
dxy = np.array([.4, .6])
368+
# Test image.
369+
# We need to work around the nonsensical (dpi-dependent) interpretation of
370+
# offsets by the Shadow class...
371+
with plt.rc_context({"savefig.dpi": "figure"}):
372+
f1, a1 = plt.subplots()
373+
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
374+
shadow = mpatches.Shadow(rect, ox=dxy[0], oy=dxy[1])
375+
a1.add_patch(rect)
376+
a1.add_patch(shadow)
377+
b1 = BytesIO()
378+
f1.savefig(b1, format="raw")
379+
# Reference image.
380+
f2, a2 = plt.subplots()
381+
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
382+
shadow = mpatches.Rectangle(
383+
xy=xy + f2.dpi / 72 * dxy, width=.5, height=.5,
384+
fc=np.asarray(mcolors.to_rgb(rect.get_fc())) * .3,
385+
ec=np.asarray(mcolors.to_rgb(rect.get_ec())) * .3,
386+
alpha=.5)
387+
a2.add_patch(shadow)
388+
a2.add_patch(rect)
389+
b2 = BytesIO()
390+
f2.savefig(b2, format="raw")
391+
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.