5
4

More than 3 years have passed since last update.

matplotlibを使って世界一有名な鶏頭図(ナイチンゲールによるクリミア戦争の死亡原因)を作る

Last updated at Posted at 2019-12-08

世界一有名な鶏頭図って?

Nightingale-mortality.jpg
引用元:https://en.wikipedia.org/wiki/Florence_Nightingale#Statistics_and_sanitary_reform

これ。
クリミア戦争における月別の死因を可視化。
赤色が負傷、青が病気、黒が他。
これを見れば病気による死亡が圧倒的に多く、負傷による死亡は比較的少ないことがわかる。

matplotlibで可視化12

# ライブラリ
import numpy as np
import matplotlib.pyplot as plt

#data, 画像からだいたいで作る
wound = [0,0,0,0,np.sqrt(0.05**2+0.03**2),1.44,2.25,np.sqrt(1.78**2+3.04**2),2.06,1.76,np.sqrt(1.07**2+0.6**2),1.07]
other = [0.74,np.sqrt(0.29**2+0.49**2),0.41,0.94,np.sqrt(0.92**2+0.53**2),1.67,2.25,np.sqrt(1.06**2+1.78**2),2.23,3.62,np.sqrt(2.01**2+3.42**2),2.7]
disease = [0,np.sqrt(0.36**2+0.61**2),0.62,4.14,np.sqrt(5.28**2+3.04**2),5.93,4.68,np.sqrt(3.09**2+5.35**2),8.5,10.84,np.sqrt(4.86**2+8.41**2),7.38]

# 色をオリジナルのものに近づける
ori_red = "#EFC6C2"
ori_gray = "#8D7D7D"
ori_blue = "#C5CCD6"

# ラベル
label = ["APRIL\n1854", "MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER",
         "DECEMBER","JANUARY 1855","FEBRUARY","MARCH"]

# 月の数、今回は12ヶ月分
N = 12
# 各円弧の中心の位置、単位円の角度で表す
theta = [-2*np.pi/12*i+2*np.pi/24*11 for i in range(12)]
# 円弧の角度、今回は等分
width = [2*np.pi/12 for _ in range(12)]

fig = plt.figure(figsize=(12,12))
# 今回は棒グラフをprojection="polar"にすることで実現
ax = fig.add_subplot(1, 1, 1, projection='polar')

# 各項目のプロット
ax.bar(theta, disease, width=width, color= ori_blue)
ax.bar(theta, other, width=width, color=ori_gray)
ax.bar(theta, wound, width=width, color=ori_red)

# legend 
ax.annotate("■ wound",xy=(0.1,0.8),xycoords='figure fraction',color=ori_red,fontsize=22)
ax.annotate("■ other",xy=(0.1,0.75),xycoords='figure fraction',color=ori_gray,fontsize=22)
ax.annotate("■ disease",xy=(0.1,0.7),xycoords='figure fraction',color=ori_blue,fontsize=22)

# 月ラベル
for i,(d,o,w,l) in enumerate(zip(disease,other,wound,label)):
    maxi = max(d,o,w)
    ref_theta = -2*np.pi/12*i+2*np.pi/24*11
    # 半径が小さすぎる場合は3で固定
    if maxi <=3:
        maxi = 3
    ax.annotate(l, xy =(ref_theta, maxi+0.2),
                ha="center",va="center",
                rotation=np.degrees(ref_theta)-90,
                fontsize=14
               )
# 軸など非表示
plt.axis('off')
plt.show()

polar_2.png

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4