LoginSignup
11
2

More than 5 years have passed since last update.

ウニプロットをmatplotlibで描く

Last updated at Posted at 2018-07-04

バイオインフォマティクスという分野の研究者ならほとんど誰でも知っている「ウニプロット」をmatplotで描いてみたくなったが、調べても方法がわからない。そもそも、画像ファイルをプロットのマーカーにする方法も調べても分からない。そこで、既存のマーカーを組み合わせてウニっぽく見えるようにしてみた。

様々なマーカーのプロット

matplotlib で使える marker を全て試してみる-pythonを参考に、マーカーの大きさとズレを微調整しながら描いてみる。

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import math
x = np.linspace(0, 2.0 * math.pi, 20)
y = np.sin(x)
from collections import OrderedDict
markers = OrderedDict([
    ('*', [200, 0, 0]),
    ('v', [100, 0, -0.02]),
    ('<', [70, -0.05, -0.01]),
    ('>', [70, 0.05, -0.01]),
    (4, [70, -0.035, 0.02]),
    (5, [70, 0.035, 0.02]),
])
for m, s in markers.items():
    plt.scatter(x + s[1], y + s[2], marker=m, c="black", s=s[0])
    plt.show()

output_2_0.png

output_2_1.png

output_2_2.png

output_2_3.png

output_2_4.png

output_2_5.png

ウニプロットの完成

以上のプロットを重ね合わせると...

from collections import OrderedDict
markers = OrderedDict([
    ('*', [200, 0, 0]),
    ('v', [100, 0, -0.02]),
    ('<', [70, -0.05, -0.01]),
    ('>', [70, 0.05, -0.01]),
    (4, [70, -0.035, 0.02]),
    (5, [70, 0.035, 0.02]),
])
for m, s in markers.items():
    plt.scatter(x + s[1], y + s[2], marker=m, c="black", s=s[0])
plt.show()

output_3_0.png

できた!!!ウニっぽい!

11
2
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
11
2