How to draw a Tetrahedron mesh by matplotlib?

2024/9/16 22:58:51

I want to plot a tetrahedron mesh by matplotlib, and the following are a simple tetrahedron mesh:

xyz = np.array([[-1,-1,-1],[ 1,-1,-1], [ 1, 1,-1],[-1, 1,-1],[-1,-1, 1],[ 1,-1, 1], [ 1, 1, 1],[-1, 1, 1]], dtype=np.float) tets = np.array([[0,1,2,6],[0,5,1,6],[0,4,5,6],[0,7,4,6],[0,3,7,6],[0,2,3,6]], dtype=np.int)

Of course, in practical applications, the number of tetrahedrons in a mesh can be large. I can't find any useful help information in google. So what is the better way to plot a tetrahedron mesh by matplotlib?

Furthermore, I can get all the triangle faces of the mesh.

tri = np.array([[0, 2, 1],[0, 1, 5],[0, 6, 1],[0, 3, 2],[0, 2, 6],[0, 6, 3],[0, 7, 3],[0, 5, 4],[0, 6, 4],[0, 4, 7],[0, 6, 5],[0, 6, 7],[1, 2, 6],[5, 1, 6],[2, 3, 6],[3, 7, 6],[4, 5, 6],[7, 4, 6]], dtype=np.int)
Answer

matplotlib is perhaps the wrong tool for the task. 3D plotting is hard, and there is, e.g., ParaView to try out. You can use meshio (a project of mine) to write your mesh to an appropriate data type:

import meshio
meshio.write('out.vtu', xyz, {'tetra': tets})

enter image description here

https://en.xdnf.cn/q/72417.html

Related Q&A

How to set seaborn jointplot axis to log scale

How to set axis to logarithmic scale in a seaborn jointplot? I cant find any log arguments in seaborn.jointplot Notebook import seaborn as sns import pandas as pddf = pd.read_csv("https://storage…

Convert decision tree directly to png [duplicate]

This question already has answers here:graph.write_pdf("iris.pdf") AttributeError: list object has no attribute write_pdf(10 answers)Closed 7 years ago.I am trying to generate a decision tree…

Python: can I modify a Tuple?

I have a 2 D tuple (Actually I thought, it was a list.. but the error says its a tuple) But anyways.. The tuple is of form: (floatnumber_val, prod_id) now I have a dictionary which contains key-> p…

Saving scatterplot animations

Ive been trying to save an animated scatterplot with matplotlib, and I would prefer that it didnt require totally different code for viewing as an animated figure and for saving a copy. The figure show…

Pandas: Bin dates into 30 minute intervals and calculate averages

I have a Pandas dataframe with two columns which are speed and time.speed date 54.72 1:33:56 49.37 1:33:59 37.03 1:34:03 24.02 7:39:58 28.02 7:40:01 24.04 7:40:04 24.02 7:40:07 25.35 …

Regular expression for UK Mobile Number - Python

I need a regular expression that only validates UK mobile numbers. A UK mobile number can be between 10-14 digits and either starts with 07, or omits the 0 and starts with 447. Importantly, if the user…

Iterate through all the rows in a table using python lxml xpath

This is the source code of the html page I want to extract data from.Webpage: http://gbgfotboll.se/information/?scr=table&ftid=51168 The table is at the bottom of the page <html><tab…

Django: Serializing a list of multiple, chained models

Given two different models, with the same parent base class. Is there any way, using either Django Rest Framework Serializers or serpy, to serialize a chained list containing instances of both the chil…

Formatting cells in Excel with Python

How do I format cells in Excel with python?In particular I need to change the font of several subsequent rows to be regular instead of bold.

What is the legality of scraping YouTube data? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about programming within the scope defined in the help center.Cl…