import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import numpy as np


import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D #<-- Note the capitalization! 




##

fig = plt.figure()

ax = Axes3D(fig)
#
X = np.arange(-1, 1, 0.05)
Y = np.arange(-1, 1, 0.05)
X, Y = np.meshgrid(X, Y)
# la fonction
Z=  X**2 - Y**2

#
surface = ax.plot_surface(X, Y, Z, cmap=cm.viridis,linewidth=0, antialiased=False)

#
ax.set_zlim(-1.01, 1.01)

#
fig.colorbar(surface, shrink=0.5, aspect=5)

plt.show()


## Exemple Ligne de niveau

fig= plt.figure()

ax = Axes3D(fig)#

X = np.arange(-2, 2, 0.125)
Y = np.arange(-2, 2, 0.125)
X, Y = np.meshgrid(X, Y)
Z=  X*X-Y*X

#
surface = ax.plot_surface(X, Y, Z, cmap=cm.viridis,linewidth=0, antialiased=False)

#
ax.set_zlim(0, 4.01)
plt.show()

## 

fig= plt.figure()

X = np.arange(-20, 20, 0.25)
Y = np.arange(-20, 20, 0.25)
X, Y = np.meshgrid(X, Y)
Z = 0.5*(Y-X)**2 + 0.5*(1-X)**2

#contour
ax =fig.gca() 
ax.set_aspect(1)

CS = ax.contour(X, Y, Z,levels=14)
ax.clabel(CS, inline=True, fontsize=10)


plt.show()

fig= plt.figure()





## gradient

X = np.arange(-20, 20, 2)
Y = np.arange(-20, 20,2)
X, Y = np.meshgrid(X, Y)
Z = 0.5*(Y-X)**2 + 0.5*(1-X)**2
u = 2*X - Y - 1
v = Y - X


# Normalize all gradients to focus on the direction not the magnitude
#norm = np.linalg.norm(np.array((u, v)), axis=0)
#u = u / norm
#v = v / norm

fig, ax = plt.subplots(1, 1)
ax.set_aspect(1)
ax.quiver(X, Y, u, v, units='xy')




plt.show()


## cobb douglas
fig= plt.figure()

ax = Axes3D(fig)#

X = np.arange(0, 2, 0.05)
Y = np.arange(0, 2, 0.05)
X, Y = np.meshgrid(X, Y)
Z=  X**(0.25)*Y**(0.75)

#
surface = ax.plot_surface(X, Y, Z, cmap=cm.viridis,linewidth=0, antialiased=False)

#
ax.set_zlim(0, 4.01)
plt.show()

## 

fig= plt.figure()


#contour
ax =fig.gca() 
ax.set_aspect(1)

CS = ax.contour(X, Y, Z,levels=14)
ax.clabel(CS, inline=True, fontsize=10)


plt.show()

fig= plt.figure()





## gradient

X = np.arange(-2, 2, 0.25)
Y = np.arange(-2, 2, 0.25)
X, Y = np.meshgrid(X, Y)
Z=  X*X-Y*X
u=2*X-Y

v=-X


# Normalize all gradients to focus on the direction not the magnitude
#norm = np.linalg.norm(np.array((u, v)), axis=0)
#u = u / norm
#v = v / norm

fig, ax = plt.subplots(1, 1)
ax.set_aspect(1)
ax.quiver(X, Y, u, v, units='xy')




plt.show()


