From ee39b153509b7e9ff60350094d18ff3251a5172f Mon Sep 17 00:00:00 2001 From: Samuel Loury Date: Wed, 27 May 2020 17:12:41 +0200 Subject: [PATCH] Use a variable instead of hardcoding the output filename --- module2/exo1/{3.png => figure_pi_mc2.png} | Bin module2/exo1/toy_document_orgmode_python_fr.org | 5 ++--- 2 files changed, 2 insertions(+), 3 deletions(-) rename module2/exo1/{3.png => figure_pi_mc2.png} (100%) diff --git a/module2/exo1/3.png b/module2/exo1/figure_pi_mc2.png similarity index 100% rename from module2/exo1/3.png rename to module2/exo1/figure_pi_mc2.png diff --git a/module2/exo1/toy_document_orgmode_python_fr.org b/module2/exo1/toy_document_orgmode_python_fr.org index 79c8fa3..1db41e2 100644 --- a/module2/exo1/toy_document_orgmode_python_fr.org +++ b/module2/exo1/toy_document_orgmode_python_fr.org @@ -36,7 +36,7 @@ Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d'app alors $P[X^2+Y^2 \le 1] = \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 file :exports both :session 56abdee0-bba4-444e-8742-69eb45eb597e +#+BEGIN_SRC python :results file :var matplot_lib_filename="figure_pi_mc2.png" :exports both :session 56abdee0-bba4-444e-8742-69eb45eb597e import matplotlib.pyplot as plt np.random.seed(seed=42) @@ -52,7 +52,6 @@ ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None) ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None) ax.set_aspect('equal') -matplot_lib_filename = "3.png" plt.savefig(matplot_lib_filename) matplot_lib_filename #+END_SRC @@ -60,7 +59,7 @@ matplot_lib_filename #+attr_html: :width 640px :height 480px #+attr_latex: :width 640px :height 480px #+RESULTS: -[[file:3.png]] +[[file:figure_pi_mc2.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