Skip to content

Zooming on a contour plot with clipping results in bad clipping #20127

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

Closed
smithsp opened this issue Apr 30, 2021 · 1 comment · Fixed by #20146
Closed

Zooming on a contour plot with clipping results in bad clipping #20127

smithsp opened this issue Apr 30, 2021 · 1 comment · Fixed by #20146

Comments

@smithsp
Copy link
Contributor

smithsp commented Apr 30, 2021

Bug report

Bug summary

If I make a contour plot, and add some clipping, then when I zoom, then the wrong parts of the plot get clipped.

Code for reproduction

# Paste your code here
import matplotlib
from matplotlib import pyplot
import numpy as np

n=100
tmp = np.random.randn(n,n)
for k in range(2):
    tmp = np.cumsum(np.cumsum(tmp,0+k),1-k)

t=np.linspace(-1,1,n)*np.pi
xc=np.cos(t)
yc=np.sin(t)

ax=pyplot.gca()
path = matplotlib.path.Path(np.transpose(np.array([xc, yc])))
patch = matplotlib.patches.PathPatch(path, facecolor='none')
ax.add_patch(patch)

x=np.linspace(-1,1,n)
y=np.linspace(-1,1,n)
cs=pyplot.contour(x,y,tmp,101)

for col in cs.collections:
    col.set_clip_path(patch)

ax.plot(xc,yc,'r')

pyplot.show()

Actual outcome

image

and then I zoom, via the zoom tool on the left half of the figure
image

Expected outcome

I expect to be able to see all of the contours on the left side that I saw before.

This did work for a previous version of matplotlib. Just tested (and works) with matplotlib 2.2.2 on QtAgg backend on python 2.7.15, as well as matplotlib 3.1.1 on QtAgg backend on python 3.6.7:
image
zoomed in:
image

Matplotlib version1

  • Operating system: Mac OSX - 10.15.7
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.3.4
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: Python 3.7.10
  • Installed via macports

Matplotlib version2

  • Operating system: Linux **** 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.3.2, 3.3.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: Python 3.7.10, 3.7.8
  • Installed via conda from conda-forge channel
@QuLogic
Copy link
Member

QuLogic commented Apr 30, 2021

Bisects to b08aa49, or #15970.

QuLogic added a commit to QuLogic/matplotlib that referenced this issue May 3, 2021
This kind of path clipping just cuts the path on the bounding box, which
produces an invalid clip path, since it is no longer closed or complete.

Fixes matplotlib#20127.
@QuLogic QuLogic added this to the v3.4.2 milestone May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants