Skip to content

Commit 45caf0e

Browse files
authored
patheffects.SimpleLineShadow calling non-existent get_foreground method from GraphicsContextBase (matplotlib#28814)
* Replaced get_forground() in patheffects.py with get_rgb() * Built a unit test to test simpleLineShadow_plot
1 parent d68c7e3 commit 45caf0e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/patheffects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
325325
gc0.copy_properties(gc)
326326

327327
if self._shadow_color is None:
328-
r, g, b = (gc0.get_foreground() or (1., 1., 1.))[:3]
328+
r, g, b = (gc0.get_rgb() or (1., 1., 1.))[:3]
329329
# Scale the colors by a factor to improve the shadow effect.
330330
shadow_rgbFace = (r * self._rho, g * self._rho, b * self._rho)
331331
else:

lib/matplotlib/tests/test_patheffects.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
from matplotlib.testing.decorators import image_comparison
5+
from matplotlib.testing.decorators import image_comparison, check_figures_equal
66
import matplotlib.pyplot as plt
77
import matplotlib.patheffects as path_effects
88
from matplotlib.path import Path
@@ -214,3 +214,19 @@ def close_group(self, s):
214214

215215
assert renderer.open_group('s') == "open_group overridden"
216216
assert renderer.close_group('s') == "close_group overridden"
217+
218+
219+
@check_figures_equal()
220+
def test_simple_line_shadow(fig_test, fig_ref):
221+
ax_ref = fig_ref.add_subplot()
222+
ax_test = fig_test.add_subplot()
223+
224+
x = np.linspace(-5, 5, 500)
225+
y = np.exp(-x**2)
226+
227+
line, = ax_test.plot(
228+
x, y, linewidth=5,
229+
path_effects=[
230+
path_effects.SimpleLineShadow(offset=(0, 0), shadow_color='blue')])
231+
232+
ax_ref.plot(x, y, linewidth=5, color='blue', alpha=0.3)

0 commit comments

Comments
 (0)