File:Pi 30K.gif
出自Wikimedia Commons
跳至導覽
跳至搜尋
Pi_30K.gif (500 × 500 像素,檔案大小:476 KB,MIME 類型:image/gif、循環、10 畫格、2.0秒)
檔案資訊
結構化資料
說明
摘要
[編輯]本GIF graphic使用Matplotlib創作。
描述Pi 30K.gif |
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 codefrom __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})
|
授權條款
[編輯]我,本作品的著作權持有者,決定用以下授權條款發佈本作品:
此檔案採用創用CC 姓名標示 3.0 未在地化版本授權條款。
- 您可以自由:
- 分享 – 複製、發佈和傳播本作品
- 重新修改 – 創作演繹作品
- 惟需遵照下列條件:
- 姓名標示 – 您必須指名出正確的製作者,和提供授權條款的連結,以及表示是否有對內容上做出變更。您可以用任何合理的方式來行動,但不得以任何方式表明授權條款是對您許可或是由您所使用。
檔案歷史
點選日期/時間以檢視該時間的檔案版本。
日期/時間 | 縮圖 | 尺寸 | 使用者 | 備註 | |
---|---|---|---|---|---|
目前 | 2017年2月16日 (四) 16:00 | 500 × 500(476 KB) | Nicoguaro(留言 | 貢獻) | Make the plot square and increase gif delay. | |
2017年2月16日 (四) 15:38 | 640 × 480(476 KB) | Nicoguaro(留言 | 貢獻) | Bigger text in the axes, and colors from ColorBrewer. Code in Python. | ||
2011年11月7日 (一) 18:29 | 500 × 500(373 KB) | Rayhem(留言 | 貢獻) | Slowed 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 | 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 |
無法覆蓋此檔案。
檔案用途
下列頁面有用到此檔案:
全域檔案使用狀況
以下其他 wiki 使用了這個檔案:
- ar.wikipedia.org 的使用狀況
- be.wikipedia.org 的使用狀況
- bg.wikipedia.org 的使用狀況
- ca.wikipedia.org 的使用狀況
- da.wikipedia.org 的使用狀況
- el.wikipedia.org 的使用狀況
- en.wikipedia.org 的使用狀況
- en.wikibooks.org 的使用狀況
- eo.wikipedia.org 的使用狀況
- eu.wikipedia.org 的使用狀況
- fa.wikipedia.org 的使用狀況
- fr.wikipedia.org 的使用狀況
- he.wikipedia.org 的使用狀況
- hi.wikipedia.org 的使用狀況
- id.wikipedia.org 的使用狀況
- it.wikipedia.org 的使用狀況
- ja.wikipedia.org 的使用狀況
- ko.wikipedia.org 的使用狀況
- pt.wikipedia.org 的使用狀況
- sh.wikipedia.org 的使用狀況
- simple.wikipedia.org 的使用狀況
- sl.wikipedia.org 的使用狀況
- sr.wikipedia.org 的使用狀況
- sv.wikipedia.org 的使用狀況
- ta.wikipedia.org 的使用狀況
- test.wikipedia.org 的使用狀況
- tr.wikipedia.org 的使用狀況
- uk.wikipedia.org 的使用狀況
- vi.wikipedia.org 的使用狀況
- www.wikidata.org 的使用狀況
- zh-yue.wikipedia.org 的使用狀況
- zh.wikipedia.org 的使用狀況