"""Provide Helper functions for plots"""

import matplotlib.pyplot as plt
import numpy as np
import seaborn

#First let us define the function f
def f(x):
    #Values x have to be passed as n times 2 array, where n is the number of different data points to be evaluated
    return np.power(x[:,0],3) + x[:,1]

def PlotContourLine(func, value=0,minx=-2, maxx=2,miny=-2, maxy=2, handle=plt):
    #This plots the contourline func(x) = value
    
    samplenum = 1000
    xrange = np.arange(minx, maxx, (maxx-minx)/samplenum)
    yrange = np.arange(miny, maxy, (maxy-miny)/samplenum)
    
    #This generates a two-dimensional mesh
    X, Y = np.meshgrid(xrange,yrange)
    
    argsForf = np.array([X.flatten(),Y.flatten()]).T
    Z = func(argsForf)
    Z = np.reshape(Z,X.shape)
    
    #handle.contour(X, Y, Z, alpha=0.5,levels=[value],linestyles='dashed',linewidths=3)
    Z = np.where(Z > value, 1, -1)
    handle.contourf(X, Y, Z, alpha=0.1)

def plot_data(x,y,handle=plt):
    """Plots a data set where
        x : coordinates in \R^2
        y : classifications taking value in {-1,+1}"""
    x_1 = x[np.where(y==-1)]
    x_2 = x[np.where(y==+1)]
    handle.scatter(x_1[:,0], x_1[:,1],marker='o')
    handle.scatter(x_2[:,0], x_2[:,1],marker='o')
