From fe7b6ca5f84f2319d0487485129758a15b715bc7 Mon Sep 17 00:00:00 2001 From: Olivia Guillin Date: Sat, 25 Apr 2020 15:35:56 +0200 Subject: [PATCH] Avec_la_figure --- module2/exo1/toy_document_orgmode_python_fr.org | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_python_fr.org b/module2/exo1/toy_document_orgmode_python_fr.org index 2548e29..63c4d38 100644 --- a/module2/exo1/toy_document_orgmode_python_fr.org +++ b/module2/exo1/toy_document_orgmode_python_fr.org @@ -1,4 +1,4 @@ -#+TITLE: À propos du calcul de $\pi$ +ho#+TITLE: À propos du calcul de $\pi$ #+LANGUAGE: fr @@ -41,8 +41,7 @@ Sinon une méthode plus simple à comprendre et ne faisant pas intervenir d'appel à la fonction sinus se base sur le fait que si $X\sim U(0,1)$ et $Y\sim U(0,1)$ alors $P[X^2+Y^2 \le1] = \pi/4$ (voir [[https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80][méthode de Monte Carlo sur wikipedia]]. Le code suivant illustre ce fait : - -#+begin_src python :results output file :var matplot_lib_filename="figure_pi_mc2.png" :exports both :session *python* +#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file "figure" ".png") :exports both import matplotlib.pyplot as plt np.random.seed(seed=42) @@ -59,15 +58,11 @@ ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None) ax.set_aspect('equal') plt.savefig(matplot_lib_filename) -print(matplot_lib_filename) +matplot_lib_filename #+end_src #+RESULTS: -[[file:Traceback (most recent call last): - File "", line 1, in - File "/var/folders/21/wtvjlyxj21b3gj703l4k0j_40000gp/T/babel-4uvhkJ/python-bYwGgQ", line 4, in - np.random.seed(seed=42) -NameError: name 'np' is not defined]] +[[file:/var/folders/21/wtvjlyxj21b3gj703l4k0j_40000gp/T/babel-0OJhDQ/figureX0cFtl.png]] Il est alors aisé d'obtenir une approximation (pas terrible) de $\pi$ en comptant combien de fois, en moyenne, $X^2+Y^2$ est inférieur à 1 : -- 2.18.1