<reponame>Floozutter/coursework<filename>usc-20211-csci-170-30111/quiz1/plot.py
import matplotlib.pyplot as plt
from math import gamma, log2
from typing import Callable

def linspace(start: float, stop: float, n: int) -> tuple[float, ...]:
    if n <= 0:
        return ()
    elif n == 1:
        return (start,)
    else:
        step = (stop - start) / (n - 1)
        return tuple(step * i + start for i in range(n))


def plot(xs: tuple[float, ...], fs: dict[str, Callable[[float], float]]) -> None:
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    for color, f in fs.items():
        ys = tuple(map(f, xs))
        ax.plot(xs, ys, color)
    fig.show()

if __name__ == "__main__":
    xs = linspace(1, 100, 100)
    fs = {
        "r": lambda n: n,
        "g": lambda n: n**2,
        "b": lambda n: gamma(n + 1),
        "c": lambda n: 2**n,
        "m": lambda n: log2(n**log2(n))
    }
    plot(xs, fs)

import matplotlib.pyplot as plt
from math import gamma, log2
from typing import Callable

def linspace(start: float, stop: float, n: int) -> tuple[float, ...]:
    if n <= 0:
        return ()
    elif n == 1:
        return (start,)
    else:
        step = (stop - start) / (n - 1)
        return tuple(step * i + start for i in range(n))


def plot(xs: tuple[float, ...], fs: dict[str, Callable[[float], float]]) -> None:
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    for color, f in fs.items():
        ys = tuple(map(f, xs))
        ax.plot(xs, ys, color)
    fig.show()

if __name__ == "__main__":
    xs = linspace(1, 100, 100)
    fs = {
        "r": lambda n: n,
        "g": lambda n: n**2,
        "b": lambda n: gamma(n + 1),
        "c": lambda n: 2**n,
        "m": lambda n: log2(n**log2(n))
    }
    plot(xs, fs)