#Importem les llibreries necessàries pel plot
import numpy as np
import matplotlib.pylab as plt
#Introduim el codi que hem fet servir anteriorment
#Les figures es presenten directament al notebook
%pylab inline
#Les figure es fan en un format adequat per impressió
%config InlineBackend.figure_format = 'svg'
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
#Definim les nostres variables
= np.linspace(-np.pi, np.pi, 10)
x = np.linspace(-np.pi, np.pi, 100)
x1 = np.sin(x)
y +=np.random.normal(0, 0.3, size=x.shape)
y=np.sin(x1)
y1#Creem el plot i exigim que el mostri
'o')
plt.plot(x,y, 'r')
plt.plot(x1,y1, plt.show()
Codi extret de Pàgina de test!
Text negreta cursiva codi
.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex eacommodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nullapariatur
.
També podem cambiar el text de color emprant HTML tags!
llista nivell 1
llista nivell 2
llista nivell 3
primer llista numerada
segon llista numerada
Es pot regular la mida amb height i width.
IMPORTANT: acabar l'enllaç amb el format de la imatge (e.g. .svg, .png, etc.).
$$ z = \frac{x}{y} $$ on $$ y =\sum_{i=0}^\infty \frac{1}{i!}x^i $$
for val in range(1,10,2):
print val
turtle
El següent codi ha de generar un finestra emergent amb una imatge com aquesta
#Turtle graphics is an implementation of the popular geometric
#drawing tools introduced in Logo, developed by Wally Feurzeig,
#Seymour Papert and Cynthia Solomon in 1967.
import turtle
def poligon(turtle, size, segments=4):
"""Draws a poligon with a turtle.
The segments have a length of size.
The number of segments can be also modified."""
= 360./segments
angle for i in range(segments):
turtle.forward(size)
turtle.left(angle)
= turtle.Screen() # Set up the window and its attributes
wn 250, 250)
wn.screensize(=280, height=280)
wn.setup(width"gray")
wn.bgcolor("Test turtle")
wn.title(
= turtle.Turtle() # Create turtle named alex
alex
= 50 #Poligon size
size
'red', 'red')
alex.color(#Draw a red square
poligon(alex, size)
'blue', 'blue')
alex.color(5) # Draw a blue pentagon
poligon(alex, size,
'orange', 'orange')
alex.color(6) # Draw an orange hexagon
poligon(alex, size,
'yellow', 'yellow')
alex.color(10, 40) # Draw nearly a yellow circle
poligon(alex,
wn.exitonclick()
Turtle star
# import for turtle
import turtle
# Starting a Working Screen
= turtle.Screen()
ws
# initializing a turtle instance
= turtle.Turtle()
geekyTurtle
# executing loop 5 times for a star
for i in range(5):
# moving turtle 100 units forward
100)
geekyTurtle.forward(
# rotating turtle 144 degree right
144) geekyTurtle.right(
raw_input()
# Verifiqueu que el següent codi demana un text per pantalla
# el retorna imprès
= input("Introdueix el teu nom: ")
nom print("> El teu nom és", nom)
Introdueix el teu nom: jupyter
> El teu nom és jupyter
matplotlib
%pylab inline
#importem les seguents funcions
import matplotlib.pyplot as plt
from numpy import sqrt
#definim la nostra variable
= range(0, 100)
x #fem el plot, éssent l'eix d'abssices el corresponent als
#valors de 'x' i el d'ordenades, sqrt(x)
'-', linewidth=2) plt.plot(x, sqrt(x),
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
[<matplotlib.lines.Line2D at 0x1e76ebfe990>]
numpy
#definim la funcio per resoldre sistemes lineals
def solve_lin_sys(mat, vec):
"""Solves linear system mat·sol = vec
by direct inversion with numpy functions"""
= inv(mat).dot(vec)
sol return sol
#variables
= array([[1., 2., 3.],[5., 3., 7.],[9., 1., 6.]])
A = array([1., 3., 5.])
b = solve_lin_sys(A,b)
x #solucions
print("A:" , A)
print("b:" , b)
print("x:", x)
A: [[1. 2. 3.]
[5. 3. 7.]
[9. 1. 6.]]
b: [1. 3. 5.]
x: [ 0.81818182 0.90909091 -0.54545455]
sympy
from IPython.display import Latex
import sympy
=sympy.Symbol('x')
x=sympy.Symbol('y')
y=(x+2*y**3)**2
f
print("Standard output:")
print(f)
print(f.diff(y))
print(f.diff(x))
print(f.diff(x).diff(x))
print(f.diff(y).diff(x))
r'Latex output: \begin{eqnarray} f(x,y) = '+ sympy.latex(f)
Latex(+ r'\\ \frac{\partial f(x,y)}{\partial x}=' + sympy.latex(f.diff(x))
+ r'\\ \frac{\partial f(x,y)}{\partial y}=' + sympy.latex(f.diff(y))
+ r'\\ \frac{\partial^2 f(x,y)}{\partial^2 x}='+ sympy.latex(f.diff(x).diff(x))
+ r'\\ \frac{\partial^2 f(x,y)}{\partial x \partial y}='+ sympy.latex(f.diff(y).diff(x))
+ r'\end{eqnarray}')
Standard output:
(x + 2*y**3)**2
12*y**2*(x + 2*y**3)
2*x + 4*y**3
2
12*y**2
<IPython.core.display.Latex at 0xaebdcfac>