[Python] Produces a circular image of 001-100

import matplotlib.pyplot as plt
import numpy as np

def draw_circle_with_number(number, filename):
    fig, ax = plt.subplots(figsize=(5, 5))
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)

    # draw circular
    circle = plt.Circle((0.5, 0.5), 0.4, color='blue', fill=False, linewidth=4)
    ax.add_artist(circle)

    # add text
    ax.text(0.5, 0.5, f'{number:03}', color='black', fontsize=90,
            ha='center', va='center', weight='bold')

    # hide axis
    ax.set_xticks([])
    ax.set_yticks([])
    ax.set_aspect('equal')

    # save to file
    plt.savefig(filename, bbox_inches='tight', pad_inches=0)
    plt.close()

# ceate 001 ~ 100
for i in range(1, 101):
    draw_circle_with_number(i, f'circle_{i:03}.png')
This entry was posted in Python. Bookmark the permalink.