← お題に戻る

説明・学習用の架空例

治療経過を、スイマープロットで見渡す

空欄は記録なし。追跡終了は死亡を意味しません。この3例から治療効果を比較しません。

入力値(単位:月、開始は全例0)
ID治療終了反応再発追跡終了
A62912
B83記録なし10
C4記録なし記録なし7
Python再現用コード(未実行)
import matplotlib.pyplot as plt
rows = [('A',6,2,9,12), ('B',8,3,None,10), ('C',4,None,None,7)]
fig, ax = plt.subplots()
for y, (name, end, response, relapse, follow) in enumerate(rows):
    assert 0 <= end <= follow
    ax.hlines(y, 0, follow, color='gray', linewidth=2)
    ax.hlines(y, 0, end, color='teal', linewidth=10)
    for event, marker in [(response, 'o'), (relapse, 'D')]:
        if event is not None:
            assert 0 <= event <= follow
            ax.plot(event, y, marker=marker, color='black', markerfacecolor='white')
    ax.plot(follow, y, marker='|', color='black', markersize=18)
ax.set_yticks(range(len(rows)), [r[0] for r in rows])
ax.set_xlabel('Months from treatment start')
ax.set_xlim(-0.5, 13)
from matplotlib.lines import Line2D
ax.legend(handles=[Line2D([0],[0],color='teal',lw=8,label='Treatment'),Line2D([0],[0],color='gray',lw=2,label='Follow-up'),Line2D([0],[0],marker='o',linestyle='',color='black',label='Response'),Line2D([0],[0],marker='D',linestyle='',color='black',label='Relapse'),Line2D([0],[0],marker='|',linestyle='',color='black',label='Follow-up end')])
fig.tight_layout()
fig.savefig('swimmer.png', dpi=200)

照合するところ