[Python] Python contour on a non-rectangular shape

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to plot pressure contours on a non-rectangular shape (this is connected to Matplotlib contourf input array shapes error and Create points grid on irregular (non-rectangular) planar surface).

    I managed to create a rectangular meshgrid, filter out the rectangular meshgrid points that in some distance away don't have any actual points and then interpolate the actual values to the remaining meshgrid points.

    I would now like to create a contour plot for these filtered out points. If I understand correctly, this could not be done with .contourf function. I have tried, but the filtered out points with their values are not structured in a correct way to do that.

    I found this option (Matplotlib set_clip_path requires patch to be plotted), for which I need to define the outline of the actual or filtered mesh data. Which I have no earthly idea how to do.

    I tried the code bellow and got the error:

    alpha = 0.95 * alphashape.optimizealpha(points_filt_coord_pairs) File "C:\Python310\lib\site-packages\alphashape\optimizealpha.py", line 100, in optimizealpha if _testalpha(points, test_alpha): File "C:\Python310\lib\site-packages\alphashape\optimizealpha.py", line 41, in _testalpha return all([polygon.intersects(point) for point in points]) TypeError: 'MultiPoint' object is not iterable.

    for a,b in zip(xx_filtered, yy_filtered):
    points_filt_coord_pairs.append((a, b))

    alpha = 0.95 * alphashape.optimizealpha(points_filt_coord_pairs)
    hull = alphashape.alphashape(points, alpha)
    hull_pts = hull.exterior.coords.xy

    Continue reading...

Compartilhe esta Página