On 16 April 2012 23:36, Damon McDougall <D.McDougall@...> wrote:
> On Monday, 16 April 2012 at 16:34, Kacper Kowalik wrote:
> On 16 Apr 2012 22:31, "Damon McDougall" <D.McDougall@...> wrote:
> > Hi Kacper,
> > Just to be clear, is it tri.Triangulation(x, y) that hangs, or is it
> It's plt.tricontour that hangs, tri.Triangulation properly issues warning
> about duplicates.
> > On Monday, 16 April 2012 at 14:28, Kacper Kowalik wrote:
> >> Hi,
> >> I haven't been able to pin point it exactly but following script:
> >> import matplotlib.pyplot as plt
> >> import matplotlib.tri as tri
> >> import numpy as np
> >> from numpy.random import uniform, seed
> >> seed(0)
> >> npts = 200
> >> x = uniform(-2,2,npts)
> >> y = uniform(-2,2,npts)
> >> z = x*np.exp(-x**2-y**2)
> >> y[1:3] = x # 4 or more duplicate points make tricontour hang!!!
> >> x[1:3] = y
> You should call z = x*np.exp(-x**2-y**2) _before_ changing the points
> you're triangulating.
> Having said that, I see the same behaviour even if I change the vertices
> before I compute z.
> >> triang = tri.Triangulation(x, y)
> >> plt.tricontour(x, y, z, 15, linewidths=0.5, colors='k')
> >> plt.show()
> >> causes infinite loop in _tri.so. It happens in matplotlib-1.1.0 as well
> >> as git HEAD.
> >> I understand that my input is not exactly valid, but I'd rather see MPL
> >> die than occupy my box for eternity ;)
> >> Best regards,
> >> Kacper
> I think the reason it's hanging is because you're trying to plot the
> contours of a function that is defined on an invalid triangulation (edges
> cross at points that are not in the vertex set). I think the best way to
> deal with this is to write a helper function to check the triangulation is
> valid. If it isn't, either tri.Triangulation(x, y) should fail, or the
> plotter should fail.
> Anybody else have any suggestions?
We can definitely do better here. I have created a issue request on github:
and will investigate further.