Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
saveall.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// Creates many canvases and save as images or pdf.
5/// This macro creates 100 canvases and store them in different images files using TCanvas::SaveAll() method.
6/// Demonstrated how different output format can be used in batch mode.
7///
8/// \macro_code
9///
10/// \author Sergey Linev
11
12void saveall()
13{
14 gROOT->SetBatch(kTRUE); // enforce batch mode to avoid appearance of multiple canvas windows
15
16 std::vector<TPad *> pads;
17
18 for(int n = 0; n < 100; ++n) {
19 auto c = new TCanvas(TString::Format("canvas%d", n), "Canvas with histogram");
20
21 auto h1 = new TH1I(TString::Format("hist%d", n), "Histogram with random data", 100, -5., 5);
22 h1->SetDirectory(nullptr);
23 h1->FillRandom("gaus", 10000);
24
25 h1->Draw();
26
27 pads.push_back(c);
28 }
29
30 TCanvas::SaveAll(pads, "image%03d.png"); // create 100 PNG images
31
32 TCanvas::SaveAll(pads, "image.svg"); // create 100 SVG images, %d pattern will be automatically append
33
34 TCanvas::SaveAll(pads, "images.root"); // create single ROOT file with all canvases
35
36 TCanvas::SaveAll(); // save all existing canvases in allcanvases.pdf file
37}
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define gROOT
Definition TROOT.h:406
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:2654
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