ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/wangdy/sys/rootstyle.py
Revision: 1.7
Committed: Thu Jul 15 16:22:47 2010 UTC (14 years, 9 months ago) by wangdy
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +36 -3 lines
Error occurred while calculating annotation data.
Log Message:
change the pad right margin to allow for COLZ;use palatte from R.Reece

File Contents

# Content
1 ##
2 ## $Log: rootstyle.py,v $
3 ## Revision 1.6 2010/05/18 17:20:12 wangdy
4 ## small updates
5 ##
6 ## Revision 1.5 2009/06/30 08:59:19 wangdy
7 ## add mitstyle and some style functions
8 ##
9 ## Revision 1.4 2009/06/26 10:13:31 wangdy
10 ## first import ildstyle; add yastyle and ildstyle directly into root logon
11 ##
12 ## Revision 1.3 2008/01/18 15:51:18 wangdy
13 ## adjust top margin of the pad w/(o) title
14 ##
15 ## Revision 1.2 2008/01/18 11:33:19 wangdy
16 ## add setting for title color
17 ##
18 ## Revision 1.1 2008/01/18 10:58:00 wangdy
19 ## first import several root style related scripts
20 ##
21 ##
22
23 """ Dayong's rootlogon file, python version """
24
25 from ROOT import *
26 from array import array
27
28
29 atlasStyle=TStyle("atlasStyle","Atlas style")
30 tdrStyle = TStyle("tdrStyle","Style for P-TDR")
31 ildStyle = TStyle("ildStyle","ILD Style")
32 yaStyle = TStyle("yaStyle","Yet Another Style, for talks")
33 MITStyle = TStyle("mitStyle","The Perfect Style for Plots ;-)");
34
35
36 def atlasstyle():
37
38 """ ATLAS stylebased on a style file from BaBar"""
39
40 global atlasStyle
41 ##.. style from RooLogon.C in workdir
42
43 ## use plain black on white colors
44 icol=0
45 atlasStyle.SetFrameBorderMode(icol)
46 atlasStyle.SetFrameFillColor(icol)
47 atlasStyle.SetCanvasBorderMode(icol)
48 atlasStyle.SetPadBorderMode(icol)
49 atlasStyle.SetPadColor(icol)
50 atlasStyle.SetCanvasColor(icol)
51 atlasStyle.SetStatColor(icol)
52 ##atlasStyle.SetFillColor(icol)
53
54 ## set the paper & margin sizes
55 atlasStyle.SetPaperSize(20,26)
56
57 ## with title:0.07 ;no title:0.05
58 atlasStyle.SetPadTopMargin(0.07)
59 atlasStyle.SetPadRightMargin(0.10)
60
61 ## with title:0.14 ;no title:0.16
62 atlasStyle.SetPadBottomMargin(0.14)
63 atlasStyle.SetPadLeftMargin(0.12)
64
65 ## use large fonts
66 ##Int_t font=72
67 font=42
68 tsize=0.05
69 atlasStyle.SetTextFont(font)
70
71
72 atlasStyle.SetTextSize(tsize)
73 atlasStyle.SetLabelFont(font,"x")
74 atlasStyle.SetTitleFont(font,"x")
75 atlasStyle.SetLabelFont(font,"y")
76 atlasStyle.SetTitleFont(font,"y")
77 atlasStyle.SetLabelFont(font,"z")
78 atlasStyle.SetTitleFont(font,"z")
79
80 atlasStyle.SetLabelSize(tsize,"x")
81 atlasStyle.SetTitleSize(tsize,"x")
82 atlasStyle.SetLabelSize(tsize,"y")
83 atlasStyle.SetTitleSize(tsize,"y")
84 atlasStyle.SetLabelSize(tsize,"z")
85 atlasStyle.SetTitleSize(tsize,"z")
86
87 ## dayong add some settings for title
88 atlasStyle.SetTitleFillColor(0)
89
90 ##use bold lines and markers
91 atlasStyle.SetMarkerStyle(20)
92 atlasStyle.SetMarkerSize(1.2)
93 atlasStyle.SetHistLineWidth(2)
94 atlasStyle.SetLineStyleString(2,"[12 12]") ## postscript dashes
95
96 ##get rid of X error bars and y error bar caps
97 ##atlasStyle.SetErrorX(0.001)
98
99 ##do not display any of the standard histogram decorations
100 atlasStyle.SetOptTitle(0)
101 ##atlasStyle.SetOptStat(1111)
102 atlasStyle.SetOptStat(0)
103 ##atlasStyle.SetOptFit(1111)
104 atlasStyle.SetOptFit(0)
105
106 atlasStyle.SetPalette(1);
107 ## put tick marks on top and RHS of plots
108 atlasStyle.SetPadTickX(1)
109 atlasStyle.SetPadTickY(1)
110 gROOT.SetStyle("atlasStyle")
111 gROOT.ForceStyle()
112
113
114 def tdrstyle():
115
116 """
117 Here is CMS ptdr style
118 """
119 global tdrStyle
120 ## tdrStyle = TStyle("tdrStyle","Style for P-TDR")
121
122 ## For the canvas:
123 tdrStyle.SetCanvasBorderMode(0)
124 tdrStyle.SetCanvasColor(kWhite)
125 tdrStyle.SetCanvasDefH(600) ##Height of canvas
126 tdrStyle.SetCanvasDefW(600) ##Width of canvas
127 tdrStyle.SetCanvasDefX(0) ##POsition on screen
128 tdrStyle.SetCanvasDefY(0)
129
130 ## For the Pad:
131 tdrStyle.SetPadBorderMode(0)
132 ## tdrStyle.SetPadBorderSize(Width_t size = 1)
133 tdrStyle.SetPadColor(kWhite)
134 tdrStyle.SetPadGridX(false)
135 tdrStyle.SetPadGridY(false)
136 tdrStyle.SetGridColor(0)
137 tdrStyle.SetGridStyle(3)
138 tdrStyle.SetGridWidth(1)
139
140 ## For the frame:
141 tdrStyle.SetFrameBorderMode(0)
142 tdrStyle.SetFrameBorderSize(1)
143 tdrStyle.SetFrameFillColor(0)
144 tdrStyle.SetFrameFillStyle(0)
145 tdrStyle.SetFrameLineColor(1)
146 tdrStyle.SetFrameLineStyle(1)
147 tdrStyle.SetFrameLineWidth(1)
148
149 ## For the histo:
150 ## tdrStyle.SetHistFillColor(1)
151 ## tdrStyle.SetHistFillStyle(0)
152 tdrStyle.SetHistLineColor(1)
153 tdrStyle.SetHistLineStyle(0)
154 tdrStyle.SetHistLineWidth(1)
155 ## tdrStyle.SetLegoInnerR(Float_t rad = 0.5)
156 ## tdrStyle.SetNumberContours(Int_t number = 20)
157 tdrStyle.SetEndErrorSize(2)
158 tdrStyle.SetMarkerStyle(20)
159 tdrStyle.SetErrorX(0.)
160 tdrStyle.SetMarkerStyle(20)
161
162 ##For the fit/function:
163 tdrStyle.SetOptFit(1)
164 tdrStyle.SetFitFormat("5.4g")
165 tdrStyle.SetFuncColor(2)
166 tdrStyle.SetFuncStyle(1)
167 tdrStyle.SetFuncWidth(1)
168
169 ##For the date:
170 tdrStyle.SetOptDate(0)
171 ## tdrStyle.SetDateX(Float_t x = 0.01)
172 ## tdrStyle.SetDateY(Float_t y = 0.01)
173
174 ## For the statistics box:
175 tdrStyle.SetOptFile(0)
176 tdrStyle.SetOptStat(0) ## To display the mean and RMS: SetOptStat("mr")
177 tdrStyle.SetStatColor(kWhite)
178 tdrStyle.SetStatFont(42)
179 tdrStyle.SetStatFontSize(0.025)
180 tdrStyle.SetStatTextColor(1)
181 tdrStyle.SetStatFormat("6.4g")
182 tdrStyle.SetStatBorderSize(1)
183 tdrStyle.SetStatH(0.1)
184 tdrStyle.SetStatW(0.15)
185 ## tdrStyle.SetStatStyle(Style_t style = 1001)
186 ## tdrStyle.SetStatX(Float_t x = 0)
187 ## tdrStyle.SetStatY(Float_t y = 0)
188
189 ## Margins:
190 tdrStyle.SetPadTopMargin(0.05)
191 tdrStyle.SetPadBottomMargin(0.15)
192 tdrStyle.SetPadLeftMargin(0.15)
193 tdrStyle.SetPadRightMargin(0.12)
194
195 ## For the Global title:
196 tdrStyle.SetOptTitle(0)
197 tdrStyle.SetTitleFont(42)
198 tdrStyle.SetTitleColor(1)
199 tdrStyle.SetTitleTextColor(1)
200 tdrStyle.SetTitleFillColor(10)
201 tdrStyle.SetTitleFontSize(0.05)
202 ## tdrStyle.SetTitleH(0) ## Set the height of the title box
203 ## tdrStyle.SetTitleW(0) ## Set the width of the title box
204 ## tdrStyle.SetTitleX(0) ## Set the position of the title box
205 ## tdrStyle.SetTitleY(0.985) ## Set the position of the title box
206 ## tdrStyle.SetTitleStyle(Style_t style = 1001)
207 ## tdrStyle.SetTitleBorderSize(2)
208
209 ## For the axis titles:
210 tdrStyle.SetTitleColor(1, "XYZ")
211 tdrStyle.SetTitleFont(42, "XYZ")
212 tdrStyle.SetTitleSize(0.06, "XYZ")
213 ## tdrStyle.SetTitleXSize(Float_t size = 0.02) ## Another way to set the size?
214 ## tdrStyle.SetTitleYSize(Float_t size = 0.02)
215 tdrStyle.SetTitleXOffset(0.9)
216 tdrStyle.SetTitleYOffset(1.25)
217 ## tdrStyle.SetTitleOffset(1.1, "Y") ## Another way to set the Offset
218
219 ## For the axis labels:
220 tdrStyle.SetLabelColor(1, "XYZ")
221 tdrStyle.SetLabelFont(42, "XYZ")
222 tdrStyle.SetLabelOffset(0.007, "XYZ")
223 tdrStyle.SetLabelSize(0.05, "XYZ")
224
225 ## For the axis:
226 tdrStyle.SetAxisColor(1, "XYZ")
227 tdrStyle.SetStripDecimals(kTRUE)
228 tdrStyle.SetTickLength(0.03, "XYZ")
229 tdrStyle.SetNdivisions(510, "XYZ")
230 tdrStyle.SetPadTickX(1) ## To get tick marks on the opposite side of the frame
231 tdrStyle.SetPadTickY(1)
232
233 ## for the palette:
234 tdrStyle.SetPalette(1);
235 ## tdrStyle.SetNumberContours(8);
236
237 ## Change for log plots:
238 tdrStyle.SetOptLogx(0)
239 tdrStyle.SetOptLogy(0)
240 tdrStyle.SetOptLogz(0)
241
242 ## Postscript options:
243 ## tdrStyle.SetPaperSize(20.,20.)
244 ## tdrStyle.SetLineScalePS(Float_t scale = 3)
245 ## tdrStyle.SetLineStyleString(Int_t i, const char* text)
246 ## tdrStyle.SetHeaderPS(const char* header)
247 ## tdrStyle.SetTitlePS(const char* pstitle)
248
249 ## tdrStyle.SetBarOffset(Float_t baroff = 0.5)
250 ## tdrStyle.SetBarWidth(Float_t barwidth = 0.5)
251 ## tdrStyle.SetPaintTextFormat(const char* format = "g")
252 ## tdrStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0)
253 ## tdrStyle.SetTimeOffset(Double_t toffset)
254 ## tdrStyle.SetHistMinimumZero(kTRUE)
255 gROOT.SetStyle("tdrStyle")
256 gROOT.ForceStyle()
257
258 def ildstyle():
259
260 """
261 Here is ILD style
262 """
263 global ildStyle
264
265
266 #set the background color to white
267 ildStyle.SetFillColor(10)
268 ildStyle.SetFrameFillColor(10)
269 ildStyle.SetCanvasColor(10)
270 ildStyle.SetPadColor(10)
271 ildStyle.SetTitleFillColor(0)
272 ildStyle.SetStatColor(10)
273
274 #dont put a colored frame around the plots
275 ildStyle.SetFrameBorderMode(0)
276 ildStyle.SetCanvasBorderMode(0)
277 ildStyle.SetPadBorderMode(0)
278 ildStyle.SetLegendBorderSize(0)
279
280 #use the primary color palette
281 ildStyle.SetPalette(1)
282
283 #set the default line color for a histogram to be black
284 ildStyle.SetHistLineColor(kBlack)
285
286 #set the default line color for a fit function to be red
287 ildStyle.SetFuncColor(kRed)
288
289 #make the axis labels black
290 ildStyle.SetLabelColor(kBlack,"xyz")
291
292 #set the default title color to be black
293 ildStyle.SetTitleColor(kBlack)
294
295 #set the margins
296 ildStyle.SetPadBottomMargin(0.18)
297 ildStyle.SetPadTopMargin(0.08)
298 ildStyle.SetPadRightMargin(0.08)
299 ildStyle.SetPadLeftMargin(0.17)
300
301 #set axis label and title text sizes
302 ildStyle.SetLabelFont(42,"xyz")
303 ildStyle.SetLabelSize(0.06,"xyz")
304 ildStyle.SetLabelOffset(0.015,"xyz")
305 ildStyle.SetTitleFont(42,"xyz")
306 ildStyle.SetTitleSize(0.07,"xyz")
307 ildStyle.SetTitleOffset(1.1,"yz")
308 ildStyle.SetTitleOffset(1.0,"x")
309 ildStyle.SetStatFont(42)
310 ildStyle.SetStatFontSize(0.07)
311 ildStyle.SetTitleBorderSize(0)
312 ildStyle.SetStatBorderSize(0)
313 ildStyle.SetTextFont(42)
314
315 #set line widths
316 ildStyle.SetFrameLineWidth(2)
317 ildStyle.SetFuncWidth(2)
318 ildStyle.SetHistLineWidth(2)
319
320 #set the number of divisions to show
321 ildStyle.SetNdivisions(506, "xy")
322
323 #turn off xy grids
324 ildStyle.SetPadGridX(0)
325 ildStyle.SetPadGridY(0)
326
327 #set the tick mark style
328 ildStyle.SetPadTickX(1)
329 ildStyle.SetPadTickY(1)
330
331 #turn off stats
332 ildStyle.SetOptStat(0)
333 ildStyle.SetOptFit(0)
334
335 #marker settings
336 ildStyle.SetMarkerStyle(20)
337 ildStyle.SetMarkerSize(0.7)
338 ildStyle.SetLineWidth(2)
339
340 gROOT.SetStyle("ildStyle")
341 gROOT.ForceStyle()
342
343 def yastyle():
344
345 """
346 Here is Yet Another style
347 """
348 global yaStyle
349
350 yaStyle.SetFillColor(0)
351 yaStyle.SetOptDate()
352 yaStyle.SetOptStat(111110)
353 yaStyle.SetOptFit(1111)
354 yaStyle.SetPadTickX(1)
355 yaStyle.SetPadTickY(1)
356 yaStyle.SetMarkerSize(0.5)
357 yaStyle.SetMarkerStyle(8)
358 yaStyle.SetGridStyle(3)
359 yaStyle.SetPaperSize(kA4)
360 yaStyle.SetStatW(0.35) # width of statistics box; default is 0.19
361 yaStyle.SetStatH(0.20) # height of statistics box; default is 0.1
362 yaStyle.SetStatFormat("6.4g") # leave default format for now
363 yaStyle.SetTitleSize(0.055, "") # size for pad title; default is 0.02
364 # Really big; useful for talks.
365 yaStyle.SetTitleSize(0.1, "") # size for pad title; default is 0.02
366 yaStyle.SetLabelSize(0.05, "XYZ") # size for axis labels; default is 0.04
367 yaStyle.SetStatFontSize(0.06) # size for stat. box
368 yaStyle.SetTitleFont(32, "XYZ") # times-bold-italic font (p. 153) for axes
369 yaStyle.SetTitleFont(32, "") # same for pad title
370 yaStyle.SetLabelFont(32, "XYZ") # same for axis labels
371 yaStyle.SetStatFont(32) # same for stat. box
372 yaStyle.SetLabelOffset(0.006, "Y") # default is 0.005
373
374 gROOT.SetStyle("yaStyle")
375 gROOT.ForceStyle()
376
377 def mitstyle():
378 global MITStyle
379 # Canvas
380 MITStyle.SetCanvasColor (0)
381 MITStyle.SetCanvasBorderSize(10)
382 MITStyle.SetCanvasBorderMode(0)
383 MITStyle.SetCanvasDefH (700)
384 MITStyle.SetCanvasDefW (700)
385 MITStyle.SetCanvasDefX (100)
386 MITStyle.SetCanvasDefY (100)
387
388 # Pads
389 MITStyle.SetPadColor (0)
390 MITStyle.SetPadBorderSize (10)
391 MITStyle.SetPadBorderMode (0)
392 MITStyle.SetPadBottomMargin(0.13)
393 MITStyle.SetPadTopMargin (0.08)
394 MITStyle.SetPadLeftMargin (0.15)
395 MITStyle.SetPadRightMargin (0.05)
396 MITStyle.SetPadGridX (0)
397 MITStyle.SetPadGridY (0)
398 MITStyle.SetPadTickX (0)
399 MITStyle.SetPadTickY (0)
400
401 # Frames
402 MITStyle.SetFrameFillStyle ( 0)
403 MITStyle.SetFrameFillColor ( 0)
404 MITStyle.SetFrameLineColor ( 1)
405 MITStyle.SetFrameLineStyle ( 0)
406 MITStyle.SetFrameLineWidth ( 1)
407 MITStyle.SetFrameBorderSize(10)
408 MITStyle.SetFrameBorderMode( 0)
409
410 # Histograms
411 MITStyle.SetHistFillColor(2)
412 MITStyle.SetHistFillStyle(0)
413 MITStyle.SetHistLineColor(1)
414 MITStyle.SetHistLineStyle(0)
415 MITStyle.SetHistLineWidth(2)
416 MITStyle.SetNdivisions(505)
417
418 # Functions
419 MITStyle.SetFuncColor(1)
420 MITStyle.SetFuncStyle(0)
421 MITStyle.SetFuncWidth(2)
422
423 # Various
424 MITStyle.SetMarkerStyle(20)
425 MITStyle.SetMarkerColor(kBlack)
426 MITStyle.SetMarkerSize (1.2)
427
428 MITStyle.SetTitleSize (0.055,"X")
429 MITStyle.SetTitleOffset(0.900,"X")
430 MITStyle.SetLabelOffset(0.005,"X")
431 MITStyle.SetLabelSize (0.050,"X")
432 MITStyle.SetLabelFont (42 ,"X")
433
434 MITStyle.SetStripDecimals(kFALSE)
435
436 MITStyle.SetTitleSize (0.055,"Y")
437 MITStyle.SetTitleOffset(1.300,"Y")
438 MITStyle.SetLabelOffset(0.010,"Y")
439 MITStyle.SetLabelSize (0.050,"Y")
440 MITStyle.SetLabelFont (42 ,"Y")
441
442 MITStyle.SetTextSize (0.055)
443 MITStyle.SetTextFont (42)
444
445 MITStyle.SetStatFont (42)
446 MITStyle.SetTitleFont (42)
447 MITStyle.SetTitleFont (42,"X")
448 MITStyle.SetTitleFont (42,"Y")
449
450 MITStyle.SetPalette (1)
451
452 MITStyle.SetOptStat (0)
453 #MITStyle.SetOptStat (111111)
454 gROOT.SetStyle("mitStyle")
455 gROOT.ForceStyle()
456
457 def set_palette(name='default', ncontours=200):
458 """Set a color palette from a given RGB list
459 stops, red, green and blue should all be lists of the same length
460 see set_decent_colors for an example"""
461
462 if name == 'gray' or name == 'grayscale':
463 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
464 red = [1.00, 0.84, 0.61, 0.34, 0.00]
465 green = [1.00, 0.84, 0.61, 0.34, 0.00]
466 blue = [1.00, 0.84, 0.61, 0.34, 0.00]
467 # elif name == "whatever":
468 # (define more palettes)
469 else:
470 # default palette, looks cool
471 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
472 red = [0.00, 0.00, 0.87, 1.00, 0.51]
473 green = [0.00, 0.81, 1.00, 0.20, 0.00]
474 blue = [0.51, 1.00, 0.12, 0.00, 0.00]
475
476 s = array('d', stops)
477 r = array('d', red)
478 g = array('d', green)
479 b = array('d', blue)
480
481 npoints = len(s)
482 TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
483 gStyle.SetNumberContours(ncontours)
484
485
486 tdrstyle()
487 set_palette()
488
489 if __name__ == '__main__':
490 ## default style
491 gROOT.SetStyle("Plain")
492 gStyle.SetOptStat(1111111)
493 gStyle.SetPadTickX(1)
494 gStyle.SetPadTickY(1)
495
496 ## activate these two style following way: better way
497 # atlasstyle()
498 # tdrstyle()
499 # ildstyle()
500 # yastyle()
501 # mitstyle()
502 ## activate these two style following way
503 ## gROOT.SetStyle("atlasStyle")
504 ## gROOT.SetStyle("tdrStyle")
505 ## gROOT.SetStyle("ildStyle")
506 ## gROOT.SetStyle("yaStyle")
507 ## gROOT.SetStyle("mitStyle")
508 ## gROOT.ForceStyle()
509
510
511