#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
x = np.linspace(-np.pi, np.pi, 10)
x1 = np.linspace(-np.pi, np.pi, 100)
y = np.sin(x)
y+=np.random.normal(0, 0.3, size=x.shape)
y1=np.sin(x1)
#Creem el plot i exigim que el mostri
plt.plot(x,y, 'o')
plt.plot(x1,y1,'r')
plt.show()Codi extret de Pàgina de test!
Text negreta cursiva codi.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex eacommodoconsequat. 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
turtleEl 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."""
angle = 360./segments
for i in range(segments):
turtle.forward(size)
turtle.left(angle)
wn = turtle.Screen() # Set up the window and its attributes
wn.screensize(250, 250)
wn.setup(width=280, height=280)
wn.bgcolor("gray")
wn.title("Test turtle")
alex = turtle.Turtle() # Create turtle named alex
size = 50 #Poligon size
alex.color('red', 'red')
poligon(alex, size) #Draw a red square
alex.color('blue', 'blue')
poligon(alex, size, 5) # Draw a blue pentagon
alex.color('orange', 'orange')
poligon(alex, size, 6) # Draw an orange hexagon
alex.color('yellow', 'yellow')
poligon(alex, 10, 40) # Draw nearly a yellow circle
wn.exitonclick()Turtle star
# import for turtle
import turtle
# Starting a Working Screen
ws = turtle.Screen()
# initializing a turtle instance
geekyTurtle = turtle.Turtle()
# executing loop 5 times for a star
for i in range(5):
# moving turtle 100 units forward
geekyTurtle.forward(100)
# rotating turtle 144 degree right
geekyTurtle.right(144)raw_input()# Verifiqueu que el següent codi demana un text per pantalla
# el retorna imprès
nom = input("Introdueix el teu 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
x = range(0, 100)
#fem el plot, éssent l'eix d'abssices el corresponent als
#valors de 'x' i el d'ordenades, sqrt(x)
plt.plot(x, sqrt(x), '-', linewidth=2)%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"""
sol = inv(mat).dot(vec)
return sol
#variables
A = array([[1., 2., 3.],[5., 3., 7.],[9., 1., 6.]])
b = array([1., 3., 5.])
x = solve_lin_sys(A,b)
#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]
sympyfrom IPython.display import Latex
import sympy
x=sympy.Symbol('x')
y=sympy.Symbol('y')
f=(x+2*y**3)**2
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))
Latex(r'Latex output: \begin{eqnarray} f(x,y) = '+ sympy.latex(f)
+ 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>