avatarFrank Ceballos

Summary

This article provides a tutorial on creating artistic Voronoi diagrams using Python, including the necessary libraries, hardware requirements, and step-by-step instructions.

Abstract

The article titled "Artistic Voronoi Diagrams in Python" is a tutorial on creating Voronoi diagrams using Python. The author was inspired by a beautiful Voronoi diagram found on the Data is Beautiful subreddit and decided to recreate it. The tutorial begins with importing necessary libraries such as NumPy, Pandas, Matplotlib, and PIL. The author then explains the process of creating a Voronoi diagram, which involves randomly drawing sites from a 2D Gaussian distribution and assigning each site a random color from one of the two palettes. The diagram is then created pixel by pixel and saved. The author notes that creating large images with a large number of cells/sites can take a long time. The article ends with an invitation to connect with the author on LinkedIn and a recommendation to try out an AI service.

Bullet points

  • The article is a tutorial on creating Voronoi diagrams using Python.
  • The author was inspired by a Voronoi diagram found on the Data is Beautiful subreddit.
  • The tutorial begins with importing necessary libraries such as NumPy, Pandas, Matplotlib, and PIL.
  • The process of creating a Voronoi diagram involves randomly drawing sites from a 2D Gaussian distribution and assigning each site a random color from one of the two palettes.
  • The diagram is then created pixel by pixel and saved.
  • Creating large images with a large number of cells/sites can take a long time.
  • The article ends with an invitation to connect with the author on LinkedIn and a recommendation to try out an AI service.

ART WITH PYTHON

Artistic Voronoi Diagrams in Python

Look mama I am an artist

Purpose: We will learn how to make a Voronoi diagram with Python.

Note: In the case you’re starting from scratch, I will advise you to follow this article and install all the necessary libraries. Finally, to get the most of this article view it on a PC or Mac with a large monitor so that you can see the details of the image.

Hardware: My workstation equipped with Inter(R)Core(TM) i7–8700 with 12 CPU @ 3.70 Ghz and NVIDIA GeForce RTX 2080.

A Word From the Author

So the other day while I was browsing the Data is Beautiful subreddit, I came across a beautiful looking Voronoi diagram. I decided that I wanted to recreate the diagram so that I could make long strips of it and used them on my Medium articles to separate sections. I could try to explain to you what Voronoi diagram is but this 3 minute video does such amazing job you should go and watch it:

With that said let’s create some stunning visuals.

Making a Voronoi Diagram

Let’s start by importing all the libraries we need.

If you get any ModuleNotFoundError let’s take care of them using Anaconda to install the missing packages. I will only go over the less common packages, since it’s likely you already have Pandas, Matplotlib, and other widely used packages installed.

Open Anaconda Prompt and navigate to the desired conda environment.

To install PIL a Python package used for image processing:

conda install -c anaconda pillow

Now let’s define the helper function that will do the bulk of the work:

You can read the doc string to understand the parameters the function takes. Click here to see some of the color palettes you can use.

To create the Voronoi diagram, sites are randomly drawn from a 2D Gaussian distribution. Then, each site is assigned a random color from one of the two palettes. Finally, the diagram is created pixel by pixel and then saved.

Now we are ready to make a cool looking diagram.

Figure 1 — A Voronoi diagram.

I would like to note that Script 3 would take a long time to run for large images and if you use a large number of cells / sites.

Closing Remarks

If you improve this or make cooler diagrams please share them with me. I would love to see the results.

You’re welcome to connect with me on LinkedIn. Until next time and code every day!

Design
Python
Art
Voronoi
Math
Recommended from ReadMedium