File:Pi 30K.gif

頁面內容唔支援其他語言。
出自維基百科,自由嘅百科全書

Pi_30K.gif(500 × 500 像素,檔案大細:476 KB ,MIME類型:image/gif、循環、10格、2.0 s)

摘要

 
This plot was created with Matplotlib.
描述
English: As points are randomly scattered inside the unit square, some fall within the unit circle. The fraction of points inside the circle over all points approaches pi/4 as the number of points goes toward infinity. This animation represents this method of computing pi out to 30,000 iterations.
來源 自己作品
作者 nicoguaro
原始碼
InfoField

Python code

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.animation as animation
from matplotlib import rcParams

# In Windows the next line should provide the full path to convert.exe
# since convert is a Windows command
#rcParams['animation.convert_path'] = "C:\Program Files\ImageMagick-6.9.3\convert.exe"
rcParams['mathtext.fontset'] = 'cm'
rcParams['font.size'] = 14


red = "#e41a1c"
blue = "#377eb8"
gray = "#eeeeee"


def update(n):
    ax.cla()
    pts = np.random.uniform(low=0, high=1, size=(2, n))
    circ = pts[:, pts[0, :]**2 + pts[1, :]**2 <= 1]
    out_circ = pts[:, pts[0, :]**2 + pts[1, :]**2 > 1]
    pi_approx = 4*circ.shape[1]/n
    circle = mpatches.Wedge((0, 0), 1, 0, 90,  color=gray)
    ax.add_artist(circle)
    plt.plot(circ[0, :], circ[1, :], marker='.', markersize=1,
             linewidth=0, color=red)
    plt.plot(out_circ[0, :], out_circ[1, :], marker='.',markersize=1,
             linewidth=0, color=blue)
    plt.title(r"$n = {}, \pi \approx {:.4f}$".format(n, pi_approx))
    plt.axis("square")
    plt.xlim(0, 1)
    plt.ylim(0, 1)


nvec = np.round(np.logspace(2, 5, 10))
nvec = [3000, 4000, 5000, 6500, 8500, 10000, 15000, 18000, 24000, 30000]
fig = plt.figure(figsize=(5, 5))
ax = fig.add_subplot(111)
ani = animation.FuncAnimation(fig, update, frames=nvec, blit=False)
ani.save("monte_carlo_pi.gif", writer='imagemagick',
         savefig_kwargs={'delay': 6})

協議

我,呢份作品嘅作者,決定用以下許可發佈呢件作品:
w:en:Creative Commons
署名
Ĉi tiu dosiero estas disponebla laŭ la permesilo Krea Komunaĵo Atribuite 3.0 Neadaptita.
你可以:
  • 去分享 – 複製、發佈同傳播呢個作品
  • 再改 – 創作演繹作品
要遵照下面嘅條件:
  • 署名 – 你一定要畀合適嘅表彰、畀返指向呢個授權條款嘅連結,同埋寫明有無改過嚟。你可以用任何合理方式去做,但唔可以用任何方式暗示授權人認可咗你或者你嘅使用方式。

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

圖中顯示嘅係

image/gif

檔案歷史

撳個日期/時間去睇響嗰個時間出現過嘅檔案。

日期/時間縮圖尺寸用戶註解
現時2017年2月16號 (四) 16:00響2017年2月16號 (四) 16:00嘅縮圖版本500 × 500(476 KB)NicoguaroMake the plot square and increase gif delay.
2017年2月16號 (四) 15:38響2017年2月16號 (四) 15:38嘅縮圖版本640 × 480(476 KB)NicoguaroBigger text in the axes, and colors from ColorBrewer. Code in Python.
2011年11月7號 (一) 18:29響2011年11月7號 (一) 18:29嘅縮圖版本500 × 500(373 KB)RayhemSlowed animation to avoid looking like a blinky page element, improved resolution, added counter for number of points, shaded points inside/outside the circle. ==Mathematica 7.0 Source== <pre> tinyColor[color_, point_] := {PointSize[Small], color, Point[
2011年3月14號 (一) 23:12響2011年3月14號 (一) 23:12嘅縮圖版本360 × 369(363 KB)CaitlinJo{{Information |Description ={{en|1=As points are randomly scattered inside the unit square, some fall within the unit circle. The fraction of points inside the circle over all points approaches pi as the number of points goes toward infinity. This ani

全域檔案使用情況

下面嘅維基都用緊呢個檔案: