How to Create or Modify a Style ?
All objects that can be drawn in a pad inherit from one or more attribute classes like ( TAttLine, TAttFill, TAttText, TAttMarker). When the objects are created, their default attributes are taken from the current style. The current style is an object of the classTStyle and can be referenced via the global variable gStyle (in TStyle.h). See the class TStyle for a complete list of the attributes that can be set in one style. ROOT provides two styles called "Default" and "Plain". The "Default" style is created simply by:
TStyle *default = new TStyle("Default","Default Style");
TStyle *plain = new TStyle("Plain","Plain Style (no colors/fill areas)"); plain->SetCanvasBorderMode(0); plain->SetPadBorderMode(0); plain->SetPadColor(0); plain->SetCanvasColor(0); plain->SetTitleColor(0); plain->SetStatColor(0);
gROOT->SetStyle(style_name);
TStyle *style = gROOT->GetStyle(style_name);
TStyle *st1 = new TStyle("st1","my style"); st1->Set.... st1->cd(); this becomes now the current style gStyle
gStyle->SetStatX(0.7); gStyle->SetStatW(0.2); gStyle->SetLabelOffset(1.2); gStyle->SetLabelFont(72);
gROOT->ForceStyle();
Let's assume you have a canvas or pad with your histogram or any other object, you can force these objects to get the attributes of the current style via:
canvas->UseCurrentStyle();
The description of the style functions should be clear from the name of the TStyle Setters or Getters. Some functions have an extended description, in particular:
- TStyle:SetLabelFont.
- TStyle:SetLineStyleString, to set the format of dashed lines.
- TStyle:SetOptStat.
- TStyle:SetPalette to change the colors palette.
- TStyle:SetTitleOffset.