公開・実測日:2026年11月22日。
どのコードを変えるとこの結果になりますか?
この図では、Pythonのstatistics.NormalDistで標準正規分位点を求めます。順位1から9の確率を(i-0.5)/9とし、0と1を避けます。N(0,1)の参照線はy=xです。
本記事では説明用のシミュレーションデータを使います。


実際の出力はどう変わりますか?
理論上の横座標は約 -1.5932〜1.5932で、標本の最大値は2.4です。右上の点は標準正規分布の参照線より上にあります。
| value |
|---|
| -1.8 |
| -0.9 |
| -0.5 |
| -0.2 |
| 0.1 |
| 0.4 |
| 0.8 |
| 1.3 |
| 2.4 |
表は入力の全行です。 (9)
この設定を使う前に何を確認しますか?
ここでは N(0,1) を基準に9つの観測を見比べます。別の平均、尺度、単位を使う場合は、当てはめや標準化の手順を説明します。
図を再現してファイルを取得するには?
書き込み可能なフォルダーで python example.py を実行します。実行環境は Python 3.12.4、Matplotlib 3.8.4、NumPy 1.26.4です。スクリプトと同じ場所に data.csv、before.png、after.png、after.pdf を作ります。
以下は本文で使ったコード、データ、実行結果のファイルです。コードを動かしたり、自分の結果と見比べたりするときに使ってください。
- example.py自分のパソコンで実行できる例のコード一式です。
- data.csv例に使った入力データです。表として開けます。
- before.png比較用の変更前の図です。
- after.png本文の設定で作成した結果の図です。
- after.pdf閲覧やページへの配置に使える PDF 形式の結果です。
- 利用条件 · LICENSE.txtコード・データ・図の利用条件と、出典・フォントの情報。
ファイルの確認
- hashes.jsonダウンロードしたファイルの完全性を確認するための照合値です。
完全な Python コード
# Original Bopbun code/data: CC0-1.0. Font rights remain separate; see LICENSE.txt.
# Tested: Python 3.12.4, Matplotlib 3.8.4, NumPy 1.26.4.
from pathlib import Path
import csv
import json
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import colors, ticker, dates
OUT=Path(__file__).resolve().parent
plt.rcdefaults()
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':11,'figure.dpi':120,
'savefig.dpi':160,'pdf.fonttype':42})
def data_file(header,rows):
with (OUT/'data.csv').open('w',newline='',encoding='utf-8') as f:
w=csv.writer(f);w.writerow(header);w.writerows(rows)
def canvas(**kw):
return plt.subplots(figsize=(7.2,4.5),layout='constrained',**kw)
from statistics import NormalDist
def make(fixed):
sample=np.array([-1.8,-.9,-.5,-.2,.1,.4,.8,1.3,2.4]);data_file(['value'],[(v,) for v in sample]);fig,ax=canvas()
theory=np.array([NormalDist().inv_cdf((i-.5)/len(sample)) for i in range(1,len(sample)+1)])
ax.scatter(theory if fixed else np.arange(1,10),np.sort(sample))
if fixed:ax.axline((0,0),slope=1,color='gray',linestyle='--',label='y = x');ax.legend()
ax.set(xlabel='Standard-normal quantile' if fixed else 'Observation rank',ylabel='Sorted sample value',title='Normal Q-Q at plotting positions (i - 0.5) / n');return fig
if __name__=='__main__':
before=make(False);after=make(True)
before.savefig(OUT/'before.png');after.savefig(OUT/'after.png')
after.savefig(OUT/'after.pdf',metadata={'CreationDate':None,'ModDate':None})
after.canvas.draw()
print(json.dumps({'axes':len(after.axes),'limits':[{'x':list(a.get_xlim()),'y':list(a.get_ylim())} for a in after.axes]}))
plt.close('all')
参照元と商用利用の条件は何ですか?
独自のコードとデータは CC0-1.0です。図は DejaVu Sans を使い、フォントの許諾は別途保持します。Matplotlib と NumPy はインストール済みの依存関係を呼び出し、配布しません。
R言語入門

