Skip to content
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

ENH: clip_path keyword for contour and contourf #26278

Merged
merged 1 commit into from Jul 14, 2023

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Jul 9, 2023

PR summary

Closes #2369. Thanks to #25247, we now only need some very minor plumbing to expose clip_path in contour and contourf.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

x = y = np.arange(-3.0, 3.01, 0.025)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2

fig, ax = plt.subplots()
patch = mpatches.RegularPolygon((0, 0), 5, radius=2, transform=ax.transData)
ax.contourf(X, Y, Z, clip_path=patch)

plt.show()

image

I'm unsure whether this should have an image test. For now, I just went for the simplest test that fails against main. I didn't add an example because we already have examples for both contours and clipping (the above, which is also the what's new entry, was adapted from this one and this one).

PR checklist

@rcomer rcomer force-pushed the contour-clip branch 2 times, most recently from 844ff44 to ea59f24 Compare July 9, 2023 11:11
@oscargus oscargus added this to the v3.8.0 milestone Jul 9, 2023
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.

If you do want in image test, it might be possible to use a check_figures_equal test instead of a new image.

Comment on lines 1874 to 1878
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER

clip_path : `~matplotlib.patches.Patch` or `.Path` or `.TransformedPath`
Set the clip path. See `~matplotlib.artist.Artist.set_clip_path`.

.. versionadded:: 3.8

Copy link
Member

Choose a reason for hiding this comment

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

I think we prefer data to be last, though I'm not sure about new arguments.

Copy link
Member Author

@rcomer rcomer Jul 13, 2023

Choose a reason for hiding this comment

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

@greglucas greglucas merged commit 5846838 into matplotlib:main Jul 14, 2023
39 checks passed
@rcomer rcomer deleted the contour-clip branch July 15, 2023 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleaning up kwargs in ContourSet
4 participants