Introduction

This blog is for introducing the a new Python library I’ve been working on, called pyray. It is a tool for creating visualizations using nothing but Python. Instead of talking more, it’s more effective to simply show you what it’s capable of with sample code. So let’s get into the visualizations.

Spheres

Spheres are perhaps the most basic of shapes. Here, we have a sphere that waves at you.

A wavy sphere

To generate this image, run the following code:

Andre’s reflection method

You have a rectangular grid and want to know the number of ways to get from bottom-left to top-right. To get the total number of ways of doing this, we can use binomial coefficients. But what if you’re only interested in paths that don’t cross some level (orange line in the figure below). That’s where Andre’s reflection method comes in. It maps the undesirable paths (the ones that do cross the orange line) to another, smaller grid. Learn more by visiting the links, or just enjoy the visualization :)

Andre’s reflection method maps “bad paths” that cross the orange line to a smaller grid.

To generate this image, run the following code snippet.

Tetartoid

Let’s go back now to 3-d objects. We know that Platonic solids are nice and symmetric, but if you add just a small amount of asymmetry to them, they look even more intriguing. Don’t take my word for it, have a look yourself at the Tetartoid.

A Tetartoid is a Dodecahedron with all faces being the same irregular pentagon

You can create this solid with the code below.

Point swarms

Shapes and grids are well and good, but the humble point can make appealing visualizations too. Here, I take some random data from two distinct classes and demonstrate how simple binary classification algorithms work.

Binary classification basically draws a boundary between two classes

Here is the code needed to generate this image.

Let me know what you think of these dancing Math GIF’s.