Use a variable instead of hardcoding the output filename

parent d6b813b3
......@@ -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 :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment