Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
saveall.C File Reference

Detailed Description

View in nbviewer Open in SWAN
This macro creates 100 canvases and store them in different images files using TCanvas::SaveAll() method Demonstrated how different output format can be used in batch mode.

void saveall()
{
gROOT->SetBatch(kTRUE); // enforce batch mode to avoid appearance of multiple canvas windows
std::vector<TPad *> pads;
for(int n = 0; n < 100; ++n) {
auto c = new TCanvas(TString::Format("canvas%d", n), "Canvas with histogram");
auto h1 = new TH1I(TString::Format("hist%d", n), "Histogram with random data", 100, -5., 5);
h1->SetDirectory(nullptr);
h1->FillRandom("gaus", 10000);
h1->Draw();
pads.push_back(c);
}
TCanvas::SaveAll(pads, "image%03d.png"); // create 100 PNG images
TCanvas::SaveAll(pads, "image.svg"); // create 100 SVG images, %d pattern will be automatically append
TCanvas::SaveAll(pads, "images.root"); // create single ROOT file with all canvases
TCanvas::SaveAll(); // save all existing canvases in allcanvases.pdf file
}
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define gROOT
Definition TROOT.h:407
The Canvas class.
Definition TCanvas.h:23
static Bool_t SaveAll(const std::vector< TPad * > &={}, const char *filename="", Option_t *option="")
Save provided pads/canvases into the image file(s) Filename can include printf argument for image num...
Definition TCanvas.cxx:2642
1-D histogram with an int per channel (see TH1 documentation)
Definition TH1.h:540
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8928
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3519
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5
Author
Sergey Linev

Definition in file saveall.C.