try:
    %matplotlib inline
except:
    !pip3 install matplotlib

"""
Explanation: <h1>Table of Contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#Installation" data-toc-modified-id="Installation-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Installation</a></span></li><li><span><a href="#Configure-Matplotlib-in-line-of-IPython-(~Jupyter)-notebook" data-toc-modified-id="Configure-Matplotlib-in-line-of-IPython-(~Jupyter)-notebook-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Configure Matplotlib in-line of IPython (~Jupyter) notebook</a></span></li><li><span><a href="#Importing-it" data-toc-modified-id="Importing-it-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Importing it</a></span></li><li><span><a href="#Drawing-data-structures-(matrices):" data-toc-modified-id="Drawing-data-structures-(matrices):-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Drawing data structures (matrices):</a></span></li><li><span><a href="#Drawing-2D-curves" data-toc-modified-id="Drawing-2D-curves-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>Drawing 2D curves</a></span></li><li><span><a href="#Drawing-3D-curves" data-toc-modified-id="Drawing-3D-curves-6"><span class="toc-item-num">6&nbsp;&nbsp;</span>Drawing 3D curves</a></span></li></ul></div>

Matplotlib
A Python 2D plotting library.
Installation
pip install matplotlib
Configure Matplotlib in-line of IPython (~Jupyter) notebook
End of explanation
"""


import matplotlib.pyplot as plt

"""
Explanation: Importing it
End of explanation
"""


try:
    import numpy as np
except:
    !pip3 install numpy
chess_board = np.zeros([8, 8], dtype=int)
chess_board[0::2, 1::2] = 1
chess_board[1::2, 0::2] = 1
plt.matshow(chess_board, cmap=plt.cm.gray)

"""
Explanation: Drawing data structures (matrices):
End of explanation
"""


resolution = 100
x = np.arange(0, 3*np.pi, np.pi/resolution)
si = np.sin(x)
co = np.cos(x)
plt.plot(x, si, c = 'r')
plt.plot(x, co, c = 'g')
plt.legend(['$\sin(x)$', '$\cos(x)$'])
plt.xlabel('radians')
plt.title('sine($x$) vs. cosine($x$)')
plt.xticks(x*resolution, ['0', '$\pi$', '$2\pi$'], rotation='horizontal')
plt.xlim(0,3*np.pi)
plt.show()

"""
Explanation: Drawing 2D curves
End of explanation
"""


x = np.array([[(x+y)/25 for x in range(256)] for y in range(256)])
si = np.sin(x)
plt.imshow(si, cmap='hot', interpolation='nearest')
plt.show()

# https://github.com/AeroPython/Taller-Aeropython-PyConEs16
def funcion(x,y):
    return np.cos(x) + np.sin(y)

x_1d = np.linspace(0, 5, 100)
y_1d = np.linspace(-2, 4, 100)
X, Y = np.meshgrid(x_1d, y_1d)
Z = funcion(X,Y)
plt.contourf(X, Y, Z, np.linspace(-2, 2, 100),cmap=plt.cm.Spectral)
plt.colorbar()
cs = plt.contour(X, Y, Z, np.linspace(-2, 2, 9), colors='k')
plt.clabel(cs)

"""
Explanation: Drawing 3D curves
End of explanation
"""


