-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Hej,
I stumbled upon this recently when trying to create a matplotlib triangulation to plot on top of my data in an FEM problem. However, I'm able to reproduce the behaviour in a simple example.
Let's say we make a unit square with four points, iterating counter-clock wise starting in the bottom left and first use the automatic triangulation by matplotlib:
using PyPlot
x = [0.0;1.0;1.0;0.0]
y = [0.0;0.0;1.0;1.0]
triang_simple = PyPlot.matplotlib.tri.Triangulation(x, y)
PyPlot.triplot(triang_simple)
This works fine, the triangulation calculated consists of two triangles, lower-left half of the square and upper-right half. Let's say we want to supply our own list of triangles ( I needed this for curved geometries where the automatic triangulation gives wrong results). The syntax is that an array of shape (Ntriang, 3) should be supplied, and the three entries for each triangle are the number of the respective points in the provided positions arrays.
x = [0.0;1.0;1.0;0.0]
y = [0.0;0.0;1.0;1.0]
triang_custom = PyPlot.matplotlib.tri.Triangulation(x, y, [1 2 3; 3 4 1])
PyPlot.triplot(triang_custom)
Running this, I get a PyError:
ValueError('triangles max element is out of bounds')
This can be fixed by subtracting 1 from all point indices, like this:
PyPlot.matplotlib.tri.Triangulation(x, y, [1 2 3; 3 4 1].- 1)
While this of course fixed my problem, it feels like an inconsistency that is a result of the difference in array counting between python and julia (starting at 0 vs starting at 1). To me, it seems like the julia interface to this function should respect julia conventions on how array elements are counted and do the subtraction internally when translating to python. Alternatively, there should be a hint in the help function that this substraction has to be done.