-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Do not set clip path if it exists #23199
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace): | |
self.patch.set_transform(affine + self._offset_transform(renderer)) | ||
self.patch.set_clip_box(gc.get_clip_rectangle()) | ||
clip_path = gc.get_clip_path() | ||
if clip_path: | ||
if clip_path and self.patch.get_clip_path() is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is bit doubtful... |
||
self.patch.set_clip_path(*clip_path) | ||
self.patch.draw(renderer) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
import matplotlib | ||
import matplotlib as mpl | ||
from matplotlib import rc_context | ||
from matplotlib import rc_context, patheffects | ||
from matplotlib._api import MatplotlibDeprecationWarning | ||
import matplotlib.colors as mcolors | ||
import matplotlib.dates as mdates | ||
|
@@ -8455,6 +8455,43 @@ def test_zorder_and_explicit_rasterization(): | |
fig.savefig(b, format='pdf') | ||
|
||
|
||
@image_comparison(["preset_clip_paths.png"], remove_text=True, style="mpl20") | ||
def test_preset_clip_paths(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we want to add an image here that we know is wrong just to have to change it again later? Some possible alternatives:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comparing
Removing annotation and then adding it doesn't really seem better? Now, the test will fail once it is fixed so one will notice this and automatically have to update it (big risk that this test will not be updated. For I'd take it that one actually would like to take the intersection of e.g. the axes patch and the provided clip path (although I am not sure if that will ever become a problem). So even if the I think this is an example that shows that it is better to use the intersection:
while current master gives or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I totally follow these recent images... The first one looks like the Polygon isn't actually containing the entire line which I would have expected from the clip, so is there still an error present? The images from
Ahh, yes, if you look at the Sorry for sending you down this rabbit hole :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a new error. Although probably this case is artificial, it is the consequence of not setting the previous default clip. So as long as we cannot do an intersection of the clip paths, we have to select which error we get. Then the question is if these compare the same? Will have to look, but pretty sure that one will have to overload the |
||
fig, ax = plt.subplots() | ||
|
||
poly = mpl.patches.Polygon( | ||
[[1, 0], [0, 1], [-1, 0], [0, -1]], facecolor="#ddffdd", | ||
edgecolor="#00ff00", linewidth=2, alpha=0.5) | ||
|
||
ax.add_patch(poly) | ||
|
||
line = mpl.lines.Line2D((-1, 1), (0.5, 0.5), clip_on=True, clip_path=poly) | ||
line.set_path_effects([patheffects.withTickedStroke()]) | ||
ax.add_artist(line) | ||
|
||
line = mpl.lines.Line2D((-1, 1), (-0.5, -0.5), color='r', clip_on=True, | ||
clip_path=poly) | ||
ax.add_artist(line) | ||
|
||
poly2 = mpl.patches.Polygon( | ||
[[-1, 1], [0, 1], [0, -0.25]], facecolor="#beefc0", alpha=0.3, | ||
edgecolor="#faded0", linewidth=2, clip_on=True, clip_path=poly) | ||
ax.add_artist(poly2) | ||
|
||
# When text clipping works, the "Annotation" text should be clipped | ||
ax.annotate('Annotation', (-0.75, -0.75), xytext=(0.1, 0.75), | ||
arrowprops={'color': 'k'}, clip_on=True, clip_path=poly) | ||
|
||
poly3 = mpl.patches.Polygon( | ||
[[0, 0], [0, 0.5], [0.5, 0.5], [0.5, 0]], facecolor="g", edgecolor="y", | ||
linewidth=2, alpha=0.3, clip_on=True, clip_path=poly) | ||
|
||
fig.add_artist(poly3, clip=True) | ||
|
||
ax.set_xlim(-1, 1) | ||
ax.set_ylim(-1, 1) | ||
|
||
|
||
@mpl.style.context('default') | ||
def test_rc_axes_label_formatting(): | ||
mpl.rcParams['axes.labelcolor'] = 'red' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that
clip_on
not only should be inkwargs
, but also be set to True?