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

tricontour and tricontourf hang #4437

Closed
divenex opened this issue May 17, 2015 · 2 comments
Closed

tricontour and tricontourf hang #4437

divenex opened this issue May 17, 2015 · 2 comments

Comments

@divenex
Copy link

divenex commented May 17, 2015

tricontour and tricontourf can hang and enter an infinite loop in special circumstances. I give below a minimal working example reproducing the problem with Python 3.4.2, Matplotlib 1.4.3 and Numpy 1.9.2. The problem seems to be due to nearly collinear points, in fact it disappear by randomly perturbing the (x, y) coordinates by a minimal amount. In the example below, the problem also disappear by simply changing the rotation angle theta from 25 to 30 degrees.

import matplotlib.pyplot as plt
import numpy as np

xi = np.linspace(-2, 2, 100)
x, y = map(np.ravel, np.meshgrid(xi, xi))
z = np.exp(-x**2 - y**2)

w = x > y - 1
x, y, z = x[w], y[w], z[w]

theta = np.radians(25)
x1 = x*np.cos(theta) - y*np.sin(theta)
y1 = x*np.sin(theta) + y*np.cos(theta)

plt.tricontour(x1, y1, z, 15, linewidths=0.5)
@ianthomas23
Copy link
Member

Bug confirmed somewhere in the Qhull to matplotlib interface. We're not always extracting the correct information from Qhull about the neighbors of triangles returned from the Qhull Delaunay triangulator. I am investigating further and will come up with a fix.

In the meantime, the problem can be avoided by adding a single line to lib/matplotlib/tri/triangulation.py. Line 55 is

self.triangles, self._neighbors = _qhull.delaunay(x, y)

After this, add the line

self._neighbors = None

This forces our code to recalculate the neighbors correctly.

@divenex: Thanks for the clear and concise bug report.

@tacaswell
Copy link
Member

Closed by #4444 Please ping to be re-opened if this is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants