# Python 3.11 --  demo matplotlib showing x-y data
# Provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-04-30  initial release

import  os;                 os.system('clear')
import  numpy               as  np
import  matplotlib.pyplot   as  plt

class Img1:

    def __init__(self):
        fig, ax = plt.subplots(figsize=(4, 2), facecolor='lightskyblue', layout='constrained')
        ax.plot ([1, 4, 2, 3])
        plt.show()


class Img2:

    def __init__(self):
        fig, ax = plt.subplots(figsize=(4, 2), facecolor='lightskyblue', layout='constrained')
        ax.plot ([1, 2.5, 3, 4], [1, 4, 2, 3])
        plt.show()


class Img3:

    def __init__(self):
        obj = {'xx': [1, 2.5, 3, 4], 'yy': [1, 4, 2, 5]}
        print(obj)

        fig, ax = plt.subplots(figsize=(4, 2), facecolor='lightskyblue', layout='constrained')
        ax.plot ('xx', 'yy', data=obj)
        plt.show()


# show y = 2x + 5
class Img4:

    def __init__(self):
        obj = dict(xx = [x     for x in range(1, 11)],
                   yy = [2*x+5 for x in range(1, 11)])
        print(obj) 

        fig, ax = plt.subplots(figsize=(4, 2), facecolor='lightskyblue', layout='constrained')
        ax.plot('xx', 'yy', data=obj)
        plt.show()


# show y1 = 2x + 5 & y2 = -2x + 20
class Img5:

    def __init__(self):
        x  = np.arange(1,11) 
        y1 =  2 * x +  5
        y2 = -2 * x + 20
        print('x :', x)
        print('y1:', y1)
        print('y2:', y2)

        fig, ax = plt.subplots(figsize=(4, 2), facecolor='lightskyblue', layout='constrained')
        ax.plot(x, y1)
        ax.plot(x, y2)
        plt.show()


# show sin(x), sin(x+120) and sin(x+240)
class Img6:

    def __init__(self):
        x = np.arange(0, 20, 0.1) 
        r = np.sin(x)
        s = np.sin(x + 2*np.pi/3)
        t = np.sin(x + 4*np.pi/3)

        fig, ax = plt.subplots(figsize=(8, 2), facecolor='lightskyblue', layout='constrained')
        ax.plot(x, r)
        ax.plot(x, s)
        ax.plot(x, t)
        plt.show()

Img6()
