- 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.
- Learning Selenium Testing Tools with Python
- Java面向?qū)ο笏枷肱c程序設(shè)計(jì)
- 算法大爆炸:面試通關(guān)步步為營(yíng)
- Interactive Applications Using Matplotlib
- BIM概論及Revit精講
- OpenResty完全開(kāi)發(fā)指南:構(gòu)建百萬(wàn)級(jí)別并發(fā)的Web應(yīng)用
- Web App Testing Using Knockout.JS
- 零基礎(chǔ)C#學(xué)習(xí)筆記
- Clojure High Performance Programming(Second Edition)
- Xamarin Cross-Platform Development Cookbook
- Sitecore Cookbook for Developers
- Mastering Object:Oriented Python(Second Edition)
- Real-time Analytics with Storm and Cassandra
- Delphi Cookbook
- Jenkins 2.x Continuous Integration Cookbook(Third Edition)