# Cette commande active l'affichage des graphiques matplotlib # dans le notebook. Elle doit apparaître une fois, au début du # notebook %matplotlib inline import matplotlib.pyplot as plt import numpy as np plt.plot([0, 1, 4, 9, 16, 25, 36, 49]) plt.plot([1, 3, 5, 7], [10, 2, 8, 5], 'r--') plt.plot([1, 3, 5, 7], [10, 2, 8, 5], 'go-', linewidth=2) plt.axis([0,11,0,11]) plt.xlabel('abscisses') plt.ylabel('ordonnees') plt.title('des donnees') plt.plot([0, 1, 4, 9, 16, 25], 'bo', label="parabole") plt.plot([0, 1, 27, 64, 125], 'rx-.', label="cubique") plt.legend() a = [x**2 for x in range(20) if x % 2 == 0] a a = np.arange(10) a b = range(10) b type(a), type(b) np.arange(0, 10, 2) 2 * a 2 * b a * a b * b x = 2 * np.pi * np.arange(0, 3, 0.01) # np.pi est la constante π y = np.sin(x) plt.plot(x, y) x = 2 * np.pi * np.arange(0, 3, 0.01) # np.pi est la constante π y = np.sin(x) plt.subplot(1,2,1) plt.plot(x, y, 'r--') plt.subplot(1,2,2) plt.plot(y, x, 'g*-'); n = np.array([0,1,2,3,4,5]) plt.subplot(2, 2, 1) plt.scatter(n, -n, s=10*n+1) plt.title("diffusion") plt.subplot(2, 2, 2) plt.step(n, n**2) plt.title("escalier") plt.subplot(2, 2, 3) plt.bar(n, n**2) plt.title("barres") plt.subplot(2, 2, 4) plt.fill_between(x, x**2, x**3, color="green"); plt.title("remplissage"); plt.pie([5, 10, 5, 80], labels=['a', 'b', 'c', 'd'], colors=['r', 'w', 'b', 'y']) n = [1, 2, 2, 3, 4, 10, 2, 1] plt.hist(n) n = [x % 30 for x in range(10000) if np.sqrt(x).is_integer()] print n plt.subplot(2,1,1) plt.hist(n) plt.subplot(2,1,2) plt.hist(n, bins=30) plt.show() import urllib2 import json prenoms = urllib2.urlopen('http://opendata.paris.fr/api/records/1.0/download?dataset=liste_des_prenoms_2004_a_2012&format=json') donnees_brutes = json.load(prenoms) len(donnees_brutes) donnees_brutes[0] donnees_brutes[0]['fields'] donnees = [d['fields'] for d in donnees_brutes] donnees[50:60]