In [1]:
a = [1, 1, 1]
b = [2, 2, 2]
a + b


Out[1]:
[1, 1, 1, 2, 2, 2]

In [2]:
1 + 1


Out[2]:
2

In [3]:
sin(30)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-884fe0852259> in <module>()
----> 1 sin(30)

NameError: name 'sin' is not defined

In [4]:
from math import sin
sin(30)


Out[4]:
-0.9880316240928618

In [5]:
import numpy as np

In [6]:
a = np.array([1, 1, 1])
b = np.array([2, 2, 2])
a + b


Out[6]:
array([3, 3, 3])

In [7]:
a = np.array([1, 1, 1])
b = np.array([2, 2, 2, 3])
a + b


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-1b4407b9ce7a> in <module>()
      1 a = np.array([1, 1, 1])
      2 b = np.array([2, 2, 2, 3])
----> 3 a + b

ValueError: operands could not be broadcast together with shapes (3,) (4,) 

In [8]:
x = np.linspace(0, 10, 100)
y = np.sin(x)

In [9]:
plot(x, y)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-500b81ce9ab8> in <module>()
----> 1 plot(x, y)

NameError: name 'plot' is not defined

In [10]:
import matplotlib.pyplot as plt

In [11]:
# Guardar gráficos vectoriales para pdf
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png', 'pdf')

In [12]:
plt.figure()
plt.plot(x, y)
plt.show()



In [13]:
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 100, 10)
y = x
z = 0.5 * x + 1

plt.figure()
plt.plot(x, y, '.')
plt.plot(x, z, '--')
plt.show()



In [14]:
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0.1, 10)
y = x ** 2

plt.figure()
plt.plot(x, y, label='data')
plt.plot(x, np.log(y), label='log')
plt.xlabel('Distancia [m]')
plt.ylabel('Tiempo [s]')
plt.legend(loc='best')
plt.grid(True)
plt.show()



In [15]:
1+1


Out[15]:
2

In [16]:
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 5 * np.pi, 0.1)
sin_x = np.sin(x)
cos_x = np.cos(x - np.pi)

plt.figure()
plt.plot(x, sin_x, '--g', label=r'$\sin(x)$')
plt.plot(x, cos_x, label=r'$\cos(x - \pi)$', color='black')
plt.legend(loc='best')
plt.show()



In [17]:
A = np.array([[1, 1], [2, 2]])
print(A)
print(A @ A)


[[1 1]
 [2 2]]
[[3 3]
 [6 6]]

In [18]:
import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0, 3 * np.pi, 100000)
r = np.sin(theta ** 2)

plt.figure()
plt.polar(theta, r)
plt.show()



In [19]:
import numpy as np
import matplotlib.pyplot as plt

rands = np.random.uniform(2, 10, size=(10000, ))

plt.figure()
plt.hist(rands, bins=80, color='green', alpha=0.5)
plt.show()



In [20]:
plt.boxplot?

In [21]:
plt.figure()
plt.boxplot([
    np.random.normal(i, 0.5, size=(100, ))
    for i in range(0, 10)
])
plt.title('Mi primer box plot')
plt.xlabel('Algo [ua]')
plt.ylabel('Algo diferente [ua]')
plt.grid()
plt.show()



In [22]:
import numpy as np
import matplotlib.pyplot as plt

plt.figure()
for i in range(2, 6):
    x = np.arange(-10, 10)
    y = x ** i
    plt.plot(x, y, label=r'$y = x ^ {{{exp}}}$'.format(exp=i))
plt.legend()
plt.grid()
plt.show()



In [23]:
import numpy as np
import matplotlib.pyplot as plt

plt.figure()
for i in range(2, 6):
    x = np.arange(0, 10)
    y = x ** (i / 2)
    plt.loglog(x, y, label=r'$y = x ^ {{{exp}}}$'.format(exp=i/2))
plt.legend()
plt.grid()
plt.show()



In [24]:
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-10, 10)
y = x ** 3
theta = np.linspace(-np.pi, np.pi)
r = np.sin(theta)
rands = np.random.chisquare(10, size=(10000, ))

plt.figure()
plt.subplot(221)
plt.plot(theta, r)
plt.xlabel(r'$\theta$')
plt.ylabel(r'$r$')
plt.subplot(223)
plt.hist(rands, normed=True)
plt.xlabel(r'$x$')
plt.ylabel(r'$p(x)$')
plt.subplot(122)
plt.loglog(x, y)
plt.xlabel(r'$\log(x)$')
plt.ylabel(r'$\log(x^3)$')
plt.tight_layout()
plt.show()



In [ ]: