Matplotlibで折れ線グラフ

今日は折れ線グラフ。

#!/usr/bin/env python
from pylab import *

x = array(range(12))
y = [2,10,4,5,30,1,6,10,9,45,8,18]
y2 =  map((lambda x: x + 10),y)

plot(x,y,'bo-')
plot(x,y2,'--g^')

legend((r'first line', r'second ling',),
        shadow = True )
ltext = gca().get_legend().get_texts()
setp(ltext[0], fontsize = 20, color = 'b')
setp(ltext[1], fontsize = 20, color = 'g')

xticks(range(12))
yticks(map((lambda x: x * 10),range(10)))
gca().get_xaxis().tick_bottom()
gca().get_yaxis().tick_left)
title("plot sample")
show()


折れ線グラフはplotメソッドでいける。
最初の引数にx軸のリスト、次の引数にy軸のリスト、最後に線のプロパティを渡す。

プロパティはAPIを見れば、分かる。
http://matplotlib.sourceforge.net/matplotlib.pylab.html#-plot

今回使ったのは

b・・blue
g・・green
o・・丸のシンボル
^・・△のシンボル
-・・直線
--・・点線

legendメソッドでグラフの右側に線の注釈をつけれる。