
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Working With Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - LaTeX
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Celluloid Library
- Matplotlib - Blitting
- Matplotlib - Toolkits
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Widgets
- Matplotlib - Cursor Widget
- Matplotlib - Annotated Cursor
- Matplotlib - Buttons Widget
- Matplotlib - Check Buttons
- Matplotlib - Lasso Selector
- Matplotlib - Menu Widget
- Matplotlib - Mouse Cursor
- Matplotlib - Multicursor
- Matplotlib - Polygon Selector
- Matplotlib - Radio Buttons
- Matplotlib - RangeSlider
- Matplotlib - Rectangle Selector
- Matplotlib - Ellipse Selector
- Matplotlib - Slider Widget
- Matplotlib - Span Selector
- Matplotlib - Textbox
- Matplotlib Plotting
- Matplotlib - Line Plots
- Matplotlib - Area Plots
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Arrow Demo
- Matplotlib - Fancy Boxes
- Matplotlib - Zorder Demo
- Matplotlib - Hatch Demo
- Matplotlib - Mmh Donuts
- Matplotlib - Ellipse Demo
- Matplotlib - Bezier Curve
- Matplotlib - Bubble Plots
- Matplotlib - Stacked Plots
- Matplotlib - Table Charts
- Matplotlib - Polar Charts
- Matplotlib - Hexagonal bin Plots
- Matplotlib - Violin Plot
- Matplotlib - Event Plot
- Matplotlib - Heatmap
- Matplotlib - Stairs Plots
- Matplotlib - Errorbar
- Matplotlib - Hinton Diagram
- Matplotlib - Contour Plot
- Matplotlib - Wireframe Plots
- Matplotlib - Surface Plots
- Matplotlib - Triangulations
- Matplotlib - Stream plot
- Matplotlib - Ishikawa Diagram
- Matplotlib - 3D Plotting
- Matplotlib - 3D Lines
- Matplotlib - 3D Scatter Plots
- Matplotlib - 3D Contour Plot
- Matplotlib - 3D Bar Plots
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - 3D Vignettes
- Matplotlib - 3D Volumes
- Matplotlib - 3D Voxels
- Matplotlib - Time Plots and Signals
- Matplotlib - Filled Plots
- Matplotlib - Step Plots
- Matplotlib - XKCD Style
- Matplotlib - Quiver Plot
- Matplotlib - Stem Plots
- Matplotlib - Visualizing Vectors
- Matplotlib - Audio Visualization
- Matplotlib - Audio Processing
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Cheatsheet
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - Triangulations
Triangulation is a process of dividing a complex shape or area into simpler parts using triangles. Imagine you have a shape, like a polygon (a closed figure with straight sides), and you want to understand or represent it in a more easy way.
Triangulation involves drawing non-overlapping triangles inside that shape, connecting its vertices (corner points) with straight lines. By doing this, you break down the original shape into a series of triangles −

Triangulations in Matplotlib
In Matplotlib, triangulation refers to the process of dividing a set of points into triangles for visualization purposes. This is useful when you want to create plots having unstructured data.
We can perform triangulation on a set of points in Matplotlib using the "Triangulation" class in the "matplotlib.tri module". Once you have the triangulation, you can use it to create plots, such as 3D surfaces or contour plots, that accurately represent the shape of your data.
Let us start by creating a triangulated surface plot.
Triangulated Surface Plot
A triangulated surface plot in Matplotlib is a 3D visualization that represents a surface using triangles. The term "triangulated" refers to the process of dividing the surface into a network of triangles, creating a simplified mesh that connects data points. This type of plot is generally used when scattered data points need to be visualized as a continuous surface.
Example
In the following example, we are creating a 3D surface plot using a set of points and Delaunay triangulation. The 'x', 'y', and 'z' arrays represent coordinates and heights of points. The Triangulation() function from "matplotlib.tri" module is used to define triangles based on these points −
import matplotlib.pyplot as plt import numpy as np import matplotlib.tri as mtri # Creating a set of points x = np.array([0, 1, 2, 3, 4, 5]) y = np.array([0, 1, 0, 1, 0, 1]) z = np.array([1, 2, 1, 2, 1, 2]) # Defining triangulation using Delaunay triangulation triang = mtri.Triangulation(x, y) # Creating a custom triangulated surface plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_trisurf(triang, z, cmap='viridis', edgecolor='black') # Adding labels ax.set_title('Triangulated Surface Plot') ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_zlabel('Z-axis') plt.show()
Output
After executing the above code, we get the following output −

Delaunay Triangulation for Scatter Plot
A delaunay triangulation for scatter plot in Matplotlib is a method of connecting a set of scattered data points with non-overlapping triangles in a manner that maximizes the minimum angle of all the triangles.
Example
In here, we are generating 20 random data points and performing Delaunay triangulation using matplotlib.tri module. The triplot() function is used to visualize the Delaunay triangulation with blue dashed lines, and the scatter() function displays the random data points in red color −
import matplotlib.pyplot as plt import numpy as np import matplotlib.tri as mtri # Generating random data points np.random.seed(42) x = np.random.rand(20) y = np.random.rand(20) # Performing Delaunay triangulation triang = mtri.Triangulation(x, y) # Creating a scatter plot with Delaunay triangulation plt.figure() plt.title('Delaunay Triangulation Scatter Plot') plt.triplot(triang, 'bo--') plt.scatter(x, y, c='red', marker='o') plt.show()
Output
Following is the output of the above code −

Contour Plot with Triangulation
A contour plot with triangulation in Matplotlib involves creating a visualization where contour lines are drawn over a surface defined by a set of points. The triangulation process is used to connect these points with triangles, forming a mesh that helps in representing the surface more smoothly.
Example
Now, we generate 20 random data points along with their corresponding function values. Next, we create a triangulated mesh using Delaunay triangulation. The triplot() function is used to display the Delaunay triangulation, while "tricontourf" generates a filled contour plot based on the function values −
import matplotlib.pyplot as plt import numpy as np import matplotlib.tri as mtri # Generating random data points np.random.seed(42) x = np.random.rand(20) y = np.random.rand(20) z = np.sin(x * y) # Defining triangulation using Delaunay triangulation triang = mtri.Triangulation(x, y) # Creating a contour plot with triangulation plt.figure() plt.title('Contour Plot with Triangulation') plt.triplot(triang, 'ko-') plt.tricontourf(triang, z, cmap='plasma') plt.show()
Output
Output of the above code is as follows −

Triangulated Line Plot
A triangulated line plot in Matplotlib involves creating a visual representation where lines are drawn to connect a set of points using triangles, forming a triangulated network. This type of plot is useful for representing data as a continuous curve, especially when the points are irregularly spaced.
Example
In the example below, we are using the triplot() function to visualize the Delaunay triangulation with red lines, creating a line plot that connects the data points −
import matplotlib.pyplot as plt import numpy as np import matplotlib.tri as mtri # Generating random data points np.random.seed(42) x = np.random.rand(20) y = np.random.rand(20) # Defining triangulation using Delaunay triangulation triang = mtri.Triangulation(x, y) # Creating a line plot with triangulation plt.figure() plt.title('Triangulated Line Plot') plt.triplot(triang, 'ro-') plt.show()
Output
The output obtained is as shown below −
