from matplotlib import pyplot as plt
import numpy as np
import math

def pic1():
    # x- and y-axis values
    x = [1, 2, 4, 8, 9]
    y = [4, 7, 3, 6, 18]
    # first, the plot must be internally constructed
    plt.plot(x ,y)
    # and displayed later
    # do explore yourself the manipulation options of the displayed plot
    plt.show()


def pic2():
    # x- and y-axis values
    x = [1, 2, 4, 8, 9]
    y = [8, 7, 6, 5, 4]
    # another set of x- and y-axis values
    x2 = [1, 2, 3, 7, 8, 9, 10]
    y2 = [4, 3, 3, 5, 6, 6, 8 ]

    # both plots go into one image
    plt.plot(x, y)
    plt.plot(x2, y2)

    # display
    plt.show()

# pic2()

def pic3():
    # make a nice "parabola"

    xValues = list( range(-4, 7) )
    # Exercise: make parabola more smooth by more dense list of xValues
    # xValues = [ ... ]   # hint: see pic4()

    yValues = [ n*n*n for n in xValues ] # list of squares
    # Exercise: change the function (e.g. to cubic) to see how the plot
    # relates to the aspect ratio

    # aspect ratio == "the ratio of the width to the height of an image or screen" [Google]
    # plt.axes().set_aspect('equal')
    plt.axes().set_aspect(0.05) # experiment with different values
    plt.plot( xValues, yValues )
    plt.show()

#pic3()

def pic4():
    # compare two parabolas"
    xValues1 = list(range(-4, 5) )
    yValues1 = [ n*n for n in xValues1 ] # list of squares
    # python  "range" does not accept float step values, apply numpy "arange"
    xValues2 = list( np.arange(-4, 5, 0.1) )
    print(xValues2)
    yValues2 = [ n*n-1 for n in xValues2 ] # list of squares, higher density

    plt.plot( xValues1, yValues1 )
    plt.plot( xValues2, yValues2 )
    plt.grid( True, which='both' )
    # see grid params:
    # https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.grid.html

    plt.axhline(y=0, color='b') # color codes -- see below
    plt.axvline(x=0, color='g')
    plt.show()

# pic4()

def pic4a():
    # zoom to the details
    xValues = list( np.arange(-10, 10, 0.0001) ) # very tiny step!!
    yValues = [ ( x*(math.sin(1/x)) )  for x in xValues ] #
    plt.plot( xValues, yValues )
    plt.axhline(y=0, color='k') # black axes
    plt.axvline(x=0, color='k')
    plt.show()

# pic4a()

def pic5():
    # also called Scatter plot (values are scattered all around the area)
    xValues = [2, 3, 3, 3, 8, 7, 8, 8, 8, 9, 8, 3, 1, 3, 3]
    yValues = [1, 3, 1, 3, 3, 1, 3, 1, 7, 8, 7, 7, 5, 3, 7]

    plt.title("PGE example plot")
    plt.xlabel("x-values")
    plt.ylabel("y-values")
    plt.plot(xValues, yValues, "ro-")    # third param (string) defines the marker color and shape
    #plt.plot(xValues, yValues, "bD:")
    plt.show()
    # markers:
    # format is made of color, shape, line style
    # color:      b g r c m y k w       (k stands for blacK)
    # shape:      . , o v ^ < > 1 2 3 4 s p * h H + x D d | _
    # line style:  -   --  -.  :
    # more details:  https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html

# pic5()

def pic5a():
    # just out of curiosity -- a spiral?
    tt = list( np.arange(1, 100, 0.1 ) )
    r = 1.0 # initial radius

    radius =  np.linspace( r, r/4, len(tt)+1 )
    # print(radius)
    #  evenly spaced numbers over a specified interval.
    # https://numpy.org/devdocs/reference/generated/numpy.linspace.html

    xValues = [ math.cos(tt[i])*radius[i] for i in range(len(tt)) ]
    yValues = [ math.sin(tt[i])*radius[i] for i in range(len(tt)) ]
    plt.plot( xValues, yValues,"ro-" )
    plt.axhline(y=0, color='k') # black axes
    plt.axvline(x=0, color='k')
    plt.show()

pic5a()



# pic1()
# pic2()
# pic3()
# pic4()
# pic4a()
# pic5()
# pic5a()

# for more examples see e.g.
# https://towardsdatascience.com/matplotlib-tutorial-learn-basics-of-pythons-powerful-plotting-library-b5d1b8f67596

