- 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.
- 大學計算機基礎(第二版)
- Git Version Control Cookbook
- JS全書:JavaScript Web前端開發指南
- 數據結構(C語言)
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- 持續輕量級Java EE開發:編寫可測試的代碼
- 智能手機APP UI設計與應用任務教程
- 快速入門與進階:Creo 4·0全實例精講
- 時空數據建模及其應用
- Visual Basic程序設計全程指南
- Java Hibernate Cookbook
- Java 7 Concurrency Cookbook
- Learn C Programming
- Azure for Architects
- HTML5+jQuery Mobile移動應用開發