Zhichen
Zhichen

Reputation: 17

Error while trying to use Matplotlib.tri.UniformRefiner.refine_field

I was trying to perform a contour refinement task, and using mtri.UniformRefiner.refine_field to do so. The codes are as following:

triang = mtri.Triangulation(mesh_pts[:, 0],mesh_pts[:, 1],triangles=tri_revise)
refiner = mtri.UniformTriRefiner(triang)
interpolator = mtri.CubicTriInterpolator(triang,grid_z)
tri_refi, grid_z = refiner.refine_field(grid_z, subdiv=4, triinterpolator=interpolator)

When I try to run the above code, an error occured: ValueError: shape mismatch: value array of shape (114,) could not be broadcast to indexing result of shape (109,)

The shape of z value, grid_z, is (114,), but I have a hard time finding out what the indexing result shape is. I was wondering if anyone can help me locate the problem. Or if there is some other way to interpolate triangle_mesh and z values, please point out as well. Thank you in advance.

Upvotes: 1

Views: 309

Answers (1)

Anas BELFADIL
Anas BELFADIL

Reputation: 106

I had the same problem when I was trying to plot a tricontour of x, y and z data. I solved it by dropping duplicate values base on x and y.

data.sort_values('z').drop_duplicates(subset=['x', 'y'], keep='last')

data here is a dataframe with columns 'x', 'y' and 'z'.

Upvotes: 1

Related Questions