See also here (ROOT/覚書)

Reference

Tips

Import pyROOT

from ROOT import gROOT, gStyle, TCanvas
....
gROOT.SetStyle("Plain")
gStyle.SetOptStat(False)

pyROOT in batch mode

import ROOT
ROOT.gROOT.SetBatch(1)

Color in pyROOT

After import ROOT, we can use

  • ROOT.kWhite
  • ROOT.kBlack
  • ROOT.kRed
  • ROOT.kBlue
  • ROOT.kGreen
  • ROOT.kYellow
  • ROOT.kMagenta
  • ROOT.kCyan

And you can also use color index from 1 to 50 as follows:

color.png

[Note] TCanvas should be closed every plot

Unexpected behavior, e.g. bad axis range, sometimes happens if the canvas is not closed correctly.
canvas = TCanvas('hoge', 'huga', 640, 480)
....
canvas.Print('hoge.eps')
canvas.Print('hoge.png')
canvas.Close()

[Note] TDatime and time display

see also here and I got almost the same results


TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  28800
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  57600
gStyle.Setenv("TZ", "")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "UTC")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "JST")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "JST-9")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  -32400
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  -64800

w/ TZ="UTC" or TZ="" or TZ="JST" and so on:

TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "UTC")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "JST")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  0
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  0
gStyle.Setenv("TZ", "JST-9")
TDatime(1995, 1, 1, 0, 0, 0).Convert()-788918400:  -32400
TDatime(1995, 1, 1, 0, 0, 0).Convert(True)-788918400:  -64800

  • None
    py_datime_none.png
  • gSystem->Setenv("TZ", "")
    py_datime.png
  • gSystem->Setenv("TZ", "UTC")
    py_datime_UTC.png
  • gSystem->Setenv("TZ", "JST")
    py_datime_JST.png
  • gSystem->Setenv("TZ", "JST-9")
    py_datime_JST-9.png

#!/usr/bin/env python

import numpy as np
import ROOT
from ROOT import TGraph, TCanvas, gPad, gStyle, TGraph, TROOT, gSystem, gROOT


def plot(tzone):
    gSystem.Setenv("TZ",tzone)
    nrows = 24 * 3600
    x = np.linspace(0., nrows, nrows)
    y = np.sin(x/nrows*2.*np.pi)

    g = TGraph(nrows, x, y)
    g.GetXaxis().SetLabelSize(0.30)
    g.GetXaxis().SetLabelColor(TROOT.kRed)
    g.GetXaxis().SetLabelOffset(-0.65)
    g.GetXaxis().SetNdivisions(-504)
    
    g.GetXaxis().SetLimits(x[0], x[-1])
    g.GetXaxis().SetTimeDisplay(1)
    g.GetXaxis().SetTimeFormat("#splitline{%y-%m-%d}{%H:%M:%S}")

    gROOT.SetStyle("Plain") ;
    gStyle.SetOptTitle(False) ;
    c = TCanvas('title', 'name', 640, 100)
    c.cd(1) ;
    gPad.SetRightMargin(0.08) ;
    gPad.SetLeftMargin(0.08) ;
    gPad.SetTopMargin(0.02) ;
    gPad.SetBottomMargin(0.02) ;
    gPad.SetGridx(1) ;
    gPad.SetGridy(1) ;
    g.Draw("APL") ;

    c.Print('py_datime_%s.png'%tzone)


for tzone in ['', 'UTC', 'JST', 'JST-9']:
    plot(tzone)

添付ファイル: filecolor.png 438件 [詳細] filepy_datime_none.png 412件 [詳細] filepy_datime_JST-9.png 408件 [詳細] filepy_datime_JST.png 416件 [詳細] filepy_datime_UTC.png 403件 [詳細] filepy_datime.png 421件 [詳細]