5
5
from numpy .testing import assert_almost_equal , assert_array_equal
6
6
import pytest
7
7
8
- from matplotlib .patches import Polygon
9
- from 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
11
10
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 )
17
14
18
15
import sys
19
16
on_win = (sys .platform == 'win32' )
@@ -443,3 +440,29 @@ def test_contains_points():
443
440
expected = path .contains_points (points , transform , radius )
444
441
result = ell .contains_points (points )
445
442
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