官术网_书友最值得收藏!

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 to do it...

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.

主站蜘蛛池模板: 葫芦岛市| 汉源县| 绵阳市| 嘉善县| 丰镇市| 娱乐| 宁蒗| 黔江区| 武夷山市| 辽阳县| 西宁市| 太和县| 巴中市| 乐亭县| 荆门市| 会理县| 达拉特旗| 灌阳县| 陵川县| 景德镇市| 华池县| 西宁市| 桃园县| 凉城县| 石楼县| 东乡族自治县| 子洲县| 酒泉市| 合川市| 保靖县| 安远县| 漯河市| 保靖县| 卢氏县| 安新县| 延长县| 宁强县| 县级市| 青铜峡市| 蓬溪县| 子长县|