LoginSignup
16
15

More than 5 years have passed since last update.

matplotlibやpylabで論文向きの白黒のグラフをプロットする

Last updated at Posted at 2013-09-21

学会は白黒でも読みやすい論文を要求します。
matplotlibやpylabは便利なのですがデフォルトで色鮮やかなグラフを出してくれるのでそのまま白黒印刷すると読みにくいです。
なのでプロット時にちょっと頑張る必要があります。

まず線のフォーマットを作成するジェネレータを作ります。

def monochrome_style_generator():
    linestyle = ['-', '--', '-.', ':']
    markerstyle = ['h' ,'2', 'v', '^', 's', '<', '>', '1', '3', '4', '8', 'p', '*', 'H', '+', ',', '.', 'x', 'o', 'D', 'd', '|', '_']
    line_idx = 0
    marker_idx = 0
    while True:
        yield 'k' + linestyle[line_idx] + markerstyle[marker_idx]
        line_idx = (line_idx + 1) % len(linestyle)
        marker_idx = (marker_idx + 1) % len(markerstyle)

こんな感じで定義したものを

plot.py
import pylab

# ジェネレータ作成
gen = monochrome_style_generator()

xval = pylab.arange(100)*.01
for x in range(6):
  # gen.next() で線のフォーマットを生成
  pylab.plot(xval, pylab.cos(x*pylab.pi*xval), gen.next())

pylab.savefig("result.png", format = 'png')

こんな感じで使ってやる事で

result.png

こんなグラフを出力できます。

16
15
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
16
15