2009年7月2日木曜日

How to use pyROOT 応用編 その1

上下に2つのグラフを表示したいなー。

そんなときはこれを使うべし。

cv.Divide( 1, 2 )


  1. #/bin/usr/env python  
  2.   
  3. import sys, math  
  4. import ROOT  
  5.   
  6. if __name__=='__main__':  
  7.   
  8.     # set graph1 style  
  9.     graph1 = ROOT.TGraph()  
  10.     graph1.SetLineWidth(2)  
  11.     graph1.SetLineColor(4)  
  12.     graph1.SetLineStyle(1)  
  13.   
  14.     # set graph2 style  
  15.     graph2 = ROOT.TGraph()  
  16.     graph2.SetLineWidth(2)  
  17.     graph2.SetLineColor(3)  
  18.     graph2.SetLineStyle(1)      
  19.   
  20.     # set title  
  21.     graph1.SetTitle("Graph Test 2 top")  
  22.     graph2.SetTitle("Graph Test 2 bottom")  
  23.   
  24.     # set data point  
  25.     for x in range(10) :  
  26.         np = graph1.GetN()  
  27.         graph1.SetPoint(np, x, x**2)  
  28.         graph2.SetPoint(np, x, x)  
  29.   
  30.     # open canvas  
  31.     cv = ROOT.TCanvas("cv""Graph Test"800800)  
  32.   
  33.     # divide canvas to two  
  34.     cv.Divide(1,2)  
  35.       
  36.     # top plot  
  37.     pad = cv.cd(1)  
  38.     pad.SetGridx(1)  
  39.     pad.SetGridy(1)  
  40.   
  41.     # plot to top pannel  
  42.     graph1.Draw("APC")  
  43.   
  44.     # set X axise of graph1  
  45.     axisY = graph1.GetYaxis()  
  46.     axisY.SetTitle("x**2")  
  47.   
  48.   
  49.     # bottom plot  
  50.     pad = cv.cd(2)  
  51.     pad.SetGridx(1)  
  52.     pad.SetGridy(1)  
  53.   
  54.     # plot to bottom pannel  
  55.     graph2.Draw("APC")  
  56.   
  57.     # set Y axise of graph1  
  58.     axisY = graph2.GetYaxis()  
  59.     axisY.SetTitle("x")  
  60.   
  61.       
  62.     # set X axis  
  63.     axisX = graph2.GetXaxis()  
  64.     axisX.SetTitle("x")  
  65.   
  66.   
  67.     # export  
  68.     cv.Print("graphtest2.png")  


0 件のコメント:

コメントを投稿