DISCLAIMER: This blog post was written by a human with the help of AI
In this blog post, we'll be exploring the plot
method of the Hypotrochoid
class in the spyrograph
library
This method allows users to create beautiful visualizations of hypotrochoids and epitrochoids using the popular matplotlib
library
We will walk through the process of creating a hypotrochoid and then use the plot
method to visualize it
Table of contents
chris-greening / spyrograph
Python library for analyzing, exploring, and visualizing epitrochoids and hypotrochoids in just a few lines of code
spyrograph: elegant mathematics and geometries
What is it?
spyrograph is a lightweight Python package that provides an expressive and flexible set of tools for drawing beautiful mathematically driven art. With just a few lines of easy-to-read code you can start analyzing, visualizing, and exploring elegant mathematics
Table of Contents
π Key features
- Expressive and consistent syntax
- Robust underlying mathematics
- Beginner and expert friendly
-
numpy
is the only required third-party installation - Clear visualizations and animations
- Flexible to a wide range of usecases
- Lightweight, just plug and play
π» Installation
pip
Install the latest stable release from PyPI using
$ pip3 install spyrograph
or clone the development version from GitHub with
$ git clone https://github.com/chris-greening/spyrograph.git
π± Quickstart
spyrograph
is designed to be expressive and easy-to-use - simply import spyrograph
and jump right into drawing elegant, complex shapesβ¦
Prerequisite imports
Before we dive into creating and plotting a hypotrochoid, let's make sure we have spyrograph
and matplotlib
installed
pip3 install spyrograph matplotlib
Creating a hypotrochoid
To create a hypotrochoid, we need to specify the parameters R
(radius of the fixed circle), r
(radius of the rolling circle), d
(distance from the rolling circle), and thetas
(a list of theta values)
Here's an example of creating a hypotrochoid:
from spyrograph import Hypotrochoid
hypotrochoid = Hypotrochoid(
R=100,
r=51,
d=75,
thetas=np.arange(0, 20 * np.pi, 0.01)
)
Plotting the hypotrochoid
Now that we have our hypotrochoid, we can use the plot
method to visualize it
This method will return a matplotlib
figure and axis objects, which we can further customize if desired
fig, ax = hypotrochoid.plot(
color="red",
linewidth=2
)
plt.show()
In this example, we've specified the color of the hypotrochoid to be blue and the line width to be 1
You can customize the appearance of the plot by passing additional keyword arguments that are accepted by the matplotlib.pyplot.plot
function
Conclusion
The plot
method in the spyrograph
library makes it incredibly easy to create visually appealing plots of hypotrochoids and epitrochoids
With just a few lines of code, we can create stunning spirograph patterns that can be used for artistic, educational, or scientific purposes
Start experimenting with different parameter values and see what amazing designs you can create!
Top comments (0)