Triangulations
Triangulations are used to plot geographical maps, which help in understanding the relative distance between various points.The longitude and latitude values are used as x, y co-ordinates to plot the points. To draw a triangle, three points are required, these are specified with the corresponding indices of the points on the plot. For a given set of co-ordinates, matplotlib can compute triangles automatically and plot the graph, or optionally, we can also provide triangles as an argument.
Getting ready
Import required libraries. We will introduce a tri-package for triangulations.
import numpy as np import matplotlib.pyplot as plt import matplotlib.tri as tri
How to do it...
The following code block generates 50 random points, creates triangles automatically and then plots the triangulation plot:
data = np.random.rand(50, 2) triangles = tri.Triangulation(data[:,0], data[:,1]) plt.triplot(triangles) plt.show()
How it works...
We first generate 50 random points using np.random.rand...