Python | Simple Rangoli Example with Matplotlib

In this tutorial, we are going to plot some rangoli drawing in Python using matplotlib.
Submitted by Anuj Singh, on August 21, 2020

Rangoli is an art form where a colored figure is drawn on the floor on festive occasions. India is a very cultural-based country and Rangoli can be found in any house during Diwali. In this article, we are introducing some very basic rangoli figures.

We can plot these figures in python and the following example illustrates the implementation.

Illustrations:

Python | Simple Rangoli Example (1)

Python | Simple Rangoli Example (2)

Python | Simple Rangoli Example (3)

Python | Simple Rangoli Example (4)

Python | Simple Rangoli Example (5)

Python code for simple rangoli example with matplotlib

import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np

n_angles = 36
n_radii = 8
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)

angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi / n_angles

x = (radii * np.cos(angles)).flatten()
y = (radii * np.sin(angles)).flatten()

triang = tri.Triangulation(x, y)

triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
                         y[triang.triangles].mean(axis=1))
                < min_radius)

fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
ax1.triplot(triang, 'b-', lw=1)
ax1.set_title('Drawing Example 1')
ax1.axis(False)


fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
ax1.triplot(triang, 'g.-', lw=1)
ax1.set_title('Drawing Example 2')
ax1.axis(False)

fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
ax1.triplot(triang, 'yo-', lw=1)
ax1.set_title('Drawing Example 3')
ax1.axis(False)


fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
ax1.triplot(triang, 'r.', lw=1)
ax1.set_title('Drawing Example 4')
ax1.axis(False)


fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
ax1.triplot(triang, 'g:', lw=1)
ax1.set_title('Drawing Example 5')
ax1.axis(False)

Output:

Output is as Figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.