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

Conversation

anijjar
Copy link
Contributor

@anijjar anijjar commented Sep 13, 2024

resolves #28793 : Replaced nonexistent get_foreground() method with get_rgb()


PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@anijjar anijjar closed this Sep 16, 2024
@anijjar anijjar reopened this Sep 16, 2024
@anijjar
Copy link
Contributor Author

anijjar commented Oct 3, 2024

@timhoffm Hi. Just wondering what else needs to get done before this fix can get merged.

@timhoffm
Copy link
Member

timhoffm commented Oct 3, 2024

Per our merge policy, we need two reviews. So this is waiting for a second core developer to approve.

@QuLogic
Copy link
Member

QuLogic commented Oct 3, 2024

Are you interested in writing a test? It looks like you have a test script in #28793, and it should be able to be turned into a figure comparison if you compare the path effect with directly plotting a line with the effective settings.

@anijjar
Copy link
Contributor Author

anijjar commented Oct 5, 2024

Are you interested in writing a test? It looks like you have a test script in #28793, and it should be able to be turned into a figure comparison if you compare the path effect with directly plotting a line with the effective settings.

Sure, that shouldn't be a problem

@anijjar
Copy link
Contributor Author

anijjar commented Oct 21, 2024

I marked the test as XFail because the '@check_figures_equal()' decorator only works for identical results. Here are screen captures of the diff.
test_simpleLineShadow_plot pdf _pdf
test_simpleLineShadow_plot pdf _pdf-failed-diff
test_simpleLineShadow_plot pdf -expected_pdf

@QuLogic
Copy link
Member

QuLogic commented Oct 22, 2024

I don't understand; the point of the test would be to confirm that the shadow is set the way you'd expect it to, and thus have equal figures.

@anijjar
Copy link
Contributor Author

anijjar commented Nov 5, 2024

I don't understand; the point of the test would be to confirm that the shadow is set the way you'd expect it to, and thus have equal figures.

I see what you mean. I changed it to plot a line with the alpha value instead for transparency.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in following up the review; I just have a few minor corrections.

Comment on lines +220 to +226
# 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)
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)

Comment on lines +228 to +234
# 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)
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)

Comment on lines 3 to 5
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
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

@tacaswell
Copy link
Member

How did this ever work?

@QuLogic
Copy link
Member

QuLogic commented Jun 5, 2025

Well, there was no test before, so no confirmation that it ever did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

patheffects.SimpleLineShadow calling non-existent get_foreground method from GraphicsContextBase
4 participants