Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DOC] Plotting common 3D mesh files in matplotlib #30738

Open
@scottshambaugh

Description

@scottshambaugh

I've been thinking about an easy way to import and plot 3D filetypes in matplotlib for a while now, and just found the excellentmeshio library which handles all the heavy lifting and file format compatibility. Filetypes supported:.inp,.msh,.avs,.cgns,.xml,.e,.exo,.f3grid,.h5m,.mdpa,.mesh,.meshb,.med,.bdf,.fem,.nas,.vol,.vol.gz,.obj,.off,.post,.post.gz,.dato,.dato.gz,.ply,.stl,.dat,.node,.ele,.svg,.su2,.ugrid,.vtk,.vtu,.wkt,.xdmf,.xmf

I think this would be a useful example to include in the gallery, and something that people would want to do quite often. But I'm not sure about our policy on adding 3rd party dependencies like this for the purposes of building the docs, and it doesn't look like the repo has seen activity over the past year.

Alternatively, I've opened upan issue over there asking if a matplotlib example could be added to the readme, and we could point to it in the 3rd party libraries. But that is less discoverable. Thoughts?

Image
#!/usr/bin/env -S uv run --script# /// script# dependencies = [#     "matplotlib",#     "meshio",#     "scipy >= 1.16.0",#     "numpy",# ]# ///importmeshioimportnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3d.art3dimportPoly3DCollectionfromscipy.spatial.transformimportRigidTransformasRT,RotationasRfrompathlibimportPath# Load the mesh for the Utah Teapot, can download from:# https://graphics.stanford.edu/courses/cs148-10-summer/as3/code/as3/teapot.objfile_path=Path(__file__).parent/"teapot.obj"mesh=meshio.read(file_path)points=mesh.pointsfaces=mesh.cells[0].data# (Optional) adjust the location and orientation of the teapotrotation=R.from_euler("xyz", [90,0,0],degrees=True)translation=np.array([0.0,0.0,0.0])transform=RT.from_components(rotation=rotation,translation=translation)points=transform.apply(points)# Create the matplotlib polygonspolys=Poly3DCollection(points[faces],facecolor="gray",edgecolor="k",linewidths=0.1)# Plot the meshfig,ax=plt.subplots(figsize=(8,6),subplot_kw={'projection':'3d'})ax.add_collection3d(polys)ax.set_aspect("equal")ax.set(title="Utah Teapot",xlabel='X',ylabel='Y',zlabel='Z')plt.show()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp