- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot 2d FEM results using matplotlib?
The Finite Element Method (FEM) is used in a variety of tasks such as modeling of different material types, testing complex geometries, visualizing the local effects acting on a small area of a design. It basically breaks a large spatial domain into simple parts called "finite elements". The simple equations that model these finite elements are then collected into a larger system of equations to model the entire domain.
To plot 2d FEM results using matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create nodes, elements and node values data points using numpy.
- Transpose the nodes' data points.
- Create a 3D filled contour plot, using tricontourf().
- To display the figure, use show() method.
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True nodes = np.array([ [0.0, 0.0], [1.0, 0.0], [2.0, 0.5], [0.0, 1.0], [1.0, 1.0], [1.7, 1.3], [1.0, 1.7]]) elements = np.array([ [1, 2, 5], [5, 4, 1], [2, 3, 6], [6, 5, 2], [4, 5, 7], [5, 6, 7]]) values = [1, 2, 1, 2, 7, 4, 5] x, y = nodes.T plt.tricontourf(x, y, elements - 1, values, 12, cmap='copper') plt.show()
It will produce the following output
- Related Articles
- How to plot a 2D histogram in Matplotlib?
- How to plot 2D math vectors with Matplotlib?
- How to use Matplotlib to plot PySpark SQL results?
- How to plot a 2D matrix in Python with colorbar Matplotlib?
- How to plot a smooth 2D color plot for z = f(x, y) in Matplotlib?
- How to plot collections.Counter histogram using Matplotlib?
- How to plot MFCC in Python using Matplotlib?
- How to plot events on time using Matplotlib?
- How to plot a wav file using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- How to get a Gantt plot using matplotlib?
- How can Tensorflow be used to plot the results using Python?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to Plot Cluster using Clustermaps class in Matplotlib