File size: 682 Bytes
6e272be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfab66f
6e272be
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import random
import numpy as np
import matplotlib.pyplot as plt

pi_facts = [
    "π is irrational and never ends!",
    "π has been calculated to over 62 trillion digits!",
    "The symbol π was first used in 1706.",
    "You can’t express π as a fraction!",
    "March 14 (3/14) is Pi Day!"
]

def random_pi_fact():
    return random.choice(pi_facts)

def generate_pi_graph():
    digits = [int(d) for d in open('pi_digits.txt').read() if d.isdigit()]
    x = list(range(len(digits)))
    y = np.cumsum([(-1)**i * d for i, d in enumerate(digits[:500])])
    fig, ax = plt.subplots()
    ax.plot(x[:len(y)], y)
    ax.set_title("π Waveform based on Digits")
    return fig