- matplotlib Plotting Cookbook
- Alexandre Devert
- 179字
- 2021-07-16 12:16:27
Plotting triangulations
Triangulations arise when dealing with spatial locations. Apart from showing distances between points and neighborhood relationships, triangulation plots can be a convenient way to represent maps. matplotlib provides a fair amount of support for triangulations.
How to do it...
As in the preceding examples, the following few lines of code are enough:
import numpy as np import matplotlib.pyplot as plt import matplotlib.tri as tri data = np.random.rand(100, 2) triangles = tri.Triangulation(data[:,0], data[:,1]) plt.triplot(triangles) plt.show()
Every time the script is run, you will see a different triangulation as the cloud of points that is triangulated is generated randomly.
The preceding script displays the following graph:

How it works...
We import the matplotlib.tri
module, which provides helper functions to compute triangulations from points. In this example, for demonstration purpose, we generate a random cloud of points using the following code:
data = np.random.rand(100, 2)
We compute a triangulation and store it in the triangles' variable with the help of the following code:
triangles = tri.Triangulation(data[:,0], data[:,1])
The pyplot.triplot()
function simply takes triangles as inputs and displays the triangulation result.
- 計算機網絡
- Bootstrap Site Blueprints Volume II
- Python爬蟲開發:從入門到實戰(微課版)
- 深入淺出Spring Boot 2.x
- Clojure for Domain:specific Languages
- Access 2010數據庫基礎與應用項目式教程(第3版)
- Python編程實戰
- Gradle for Android
- 零基礎學單片機C語言程序設計
- UML 基礎與 Rose 建模案例(第3版)
- Java系統化項目開發教程
- Swift Playgrounds少兒趣編程
- INSTANT Silverlight 5 Animation
- Kotlin Programming By Example
- Application Development with Swift