Esta será nossa primeira aula. Esse é um exemplo do que podemos fazer em Python.
Antes de mais nada inicie o servidor do iPython notebook com: ipython notebook Testes
-> dando dois cliques podemos editar o que esta nessa célula.
aqui podemos editar texto usando latex: $$c = \sqrt{a^2 + b^2}$$
$c = \sqrt{a^2 + b^2}$
In [3]:
# voce pode salvar esse notebook como uma apostila, usando comentarios.
In [4]:
from IPython.display import display, Math, Latex
In [5]:
%%latex
$$c = \sqrt{a^2 + b^2}$$
In [6]:
#esse comando inclui os plots na pagina do notebook
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('Um grafico simples')
plt.show()
In [7]:
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radiuses
plt.scatter(x, y, s=area, alpha=0.5)
plt.title('Um grafico XY simples')
plt.show()
In [8]:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contourf(X, Y, Z, cmap=cm.coolwarm)
ax.clabel(cset, fontsize=9, inline=1)
plt.show()
In [11]:
from mayavi import mlab
x, y, z = np.ogrid[-10:10:50j, -10:10:50j, -10:10:50j]
s = np.sin(x*y*z)/(x*y*z)
src = mlab.pipeline.scalar_field(s)
mlab.pipeline.iso_surface(src, contours=[s.min()+0.1*s.ptp(), ], opacity=0.3)
mlab.pipeline.iso_surface(src, contours=[s.max()-0.1*s.ptp(), ],)
mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(s),
plane_orientation='x_axes',
slice_index=20)
mlab.show()
In [12]:
from IPython.display import YouTubeVideo
YouTubeVideo("oYTs9HwFGbY")
Out[12]:
In [13]:
0.1 + 0.2
Out[13]:
This is because 0.1 can't be represent in Binary form exactly. In base 2, or Binary, 0.1 is the infinity repeating numbers
0.0001100110011001100110011001100110011001100110011... So, Python decided to round this off instead.
Leia mais sobre isso aqui: https://docs.python.org/2/tutorial/floatingpoint.html
In [18]:
import numpy as np
import matplotlib.pyplot as plt
points = np.array([(1, 1), (2, 4), (3, 1), (9, 3),(6.5,-10)])
# get x and y vectors
x = points[:,0]
y = points[:,1]
# calculate polynomial
z = np.polyfit(x, y, 3)
f = np.poly1d(z)
# calculate new x's and y's
x_new = np.linspace(x[0], x[-1], 50)
y_new = f(x_new)
plt.plot(x,y,'o', x_new, y_new)
plt.xlim([x[0]-1, x[-1] + 1 ])
plt.show()
In [ ]: