0
0
SciPydata~30 mins

Voronoi diagrams in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Voronoi Diagrams with SciPy
📖 Scenario: Imagine you are working for a city planning team. You want to divide a park into areas closest to each of several fountains. This helps decide where to place benches and signs so visitors are near a water source.
🎯 Goal: You will create a set of points representing fountains, configure a boundary size, compute the Voronoi diagram using SciPy, and finally display the Voronoi regions.
📋 What You'll Learn
Create a list of fountain coordinates as tuples
Set a boundary size variable for the park area
Use SciPy's Voronoi function to compute the diagram
Plot the Voronoi diagram using matplotlib
💡 Why This Matters
🌍 Real World
Voronoi diagrams help divide spaces based on proximity, useful in city planning, resource allocation, and biology.
💼 Career
Data scientists and GIS specialists use Voronoi diagrams to analyze spatial data and optimize locations.
Progress0 / 4 steps
1
Create fountain coordinates
Create a list called fountains with these exact tuples: (2, 3), (5, 5), (1, 8), (7, 2), and (6, 6).
SciPy
Need a hint?

Use a Python list with tuples for each fountain's (x, y) position.

2
Set park boundary size
Create a variable called boundary_size and set it to 10 to represent the park's width and height.
SciPy
Need a hint?

This variable will help later when plotting the park area.

3
Compute the Voronoi diagram
Import Voronoi from scipy.spatial. Then create a variable called vor by passing fountains to Voronoi().
SciPy
Need a hint?

Use from scipy.spatial import Voronoi and then call Voronoi(fountains).

4
Plot the Voronoi diagram
Import matplotlib.pyplot as plt. Use plt.figure() to create a figure. Then use scipy.spatial.voronoi_plot_2d(vor) to plot the diagram. Finally, set the x and y limits to 0 and boundary_size and call plt.show() to display.
SciPy
Need a hint?

Use voronoi_plot_2d(vor) to draw the diagram and plt.show() to display it.