Thanks to visit codestin.com
Credit goes to github.com

Skip to content

patheffects.SimpleLineShadow calling non-existent get_foreground method from GraphicsContextBase #28814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/patheffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
gc0.copy_properties(gc)

if self._shadow_color is None:
r, g, b = (gc0.get_foreground() or (1., 1., 1.))[:3]
r, g, b = (gc0.get_rgb() or (1., 1., 1.))[:3]

Check warning on line 328 in lib/matplotlib/patheffects.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/patheffects.py#L328

Added line #L328 was not covered by tests
# Scale the colors by a factor to improve the shadow effect.
shadow_rgbFace = (r * self._rho, g * self._rho, b * self._rho)
else:
Expand Down
22 changes: 20 additions & 2 deletions lib/matplotlib/tests/test_patheffects.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import platform

import numpy as np

from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import image_comparison, check_figures_equal
import matplotlib.pyplot as plt
Comment on lines 3 to 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs in the third block, with first-party imports:

Suggested change
import numpy as np
from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import image_comparison, check_figures_equal
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison, check_figures_equal

import matplotlib.patheffects as path_effects
from matplotlib.path import Path
Expand Down Expand Up @@ -214,3 +213,22 @@ def close_group(self, s):

assert renderer.open_group('s') == "open_group overridden"
assert renderer.close_group('s') == "close_group overridden"


@check_figures_equal()
def test_simpleLineShadow_plot(fig_test, fig_ref):
# Create the plots
ax_ref = fig_ref.add_subplot()
ax_test = fig_test.add_subplot()

# Generate Gaussian distribution data
x = np.linspace(-5, 5, 500)
y = np.exp(-x**2)
Comment on lines +220 to +226
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think these comments are necessary.

Suggested change
# Create the plots
ax_ref = fig_ref.add_subplot()
ax_test = fig_test.add_subplot()
# Generate Gaussian distribution data
x = np.linspace(-5, 5, 500)
y = np.exp(-x**2)
ax_ref = fig_ref.add_subplot()
ax_test = fig_test.add_subplot()
x = np.linspace(-5, 5, 500)
y = np.exp(-x**2)


# Plot the Gaussian line with the SimpleLineShadow path effect
line, = ax_test.plot(x, y, linewidth=5)
line.set_path_effects([path_effects.SimpleLineShadow(
offset=(0, 0), shadow_color='blue', rho=0.5)])

# Plot the Gaussian line simply
ax_ref.plot(x, y, linewidth=5, color='blue', alpha=0.3)
Comment on lines +228 to +234
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rho is not used since shadow_color is specified. You can also pass this directly to plot:

Suggested change
# Plot the Gaussian line with the SimpleLineShadow path effect
line, = ax_test.plot(x, y, linewidth=5)
line.set_path_effects([path_effects.SimpleLineShadow(
offset=(0, 0), shadow_color='blue', rho=0.5)])
# Plot the Gaussian line simply
ax_ref.plot(x, y, linewidth=5, color='blue', alpha=0.3)
ax_test.plot(x, y, linewidth=5,
path_effects=[
path_effects.SimpleLineShadow(offset=(0, 0), shadow_color='blue')])
ax_ref.plot(x, y, linewidth=5, color='blue', alpha=0.3)

Loading