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/// This macro creates 100 canvases and store them in different images files using TCanvas::SaveAll() method
5/// Demonstrated how different output format can be used in batch mode.
6///
7/// \macro_code
8///
9/// \author Sergey Linev
10
11void saveall()
12{
13 gROOT->SetBatch(kTRUE); // enforce batch mode to avoid appearance of multiple canvas windows
14
15 std::vector<TPad *> pads;
16
17 for(int n = 0; n < 100; ++n) {
18 auto c = new TCanvas(TString::Format("canvas%d", n), "Canvas with histogram");
19
20 auto h1 = new TH1I(TString::Format("hist%d", n), "Histogram with random data", 100, -5., 5);
21 h1->SetDirectory(nullptr);
22 h1->FillRandom("gaus", 10000);
23
24 h1->Draw();
25
26 pads.push_back(c);
27 }
28
29 TCanvas::SaveAll(pads, "image%03d.png"); // create 100 PNG images
30
31 TCanvas::SaveAll(pads, "image.svg"); // create 100 SVG images, %d pattern will be automatically append
32
33 TCanvas::SaveAll(pads, "images.root"); // create single ROOT file with all canvases
34
35 TCanvas::SaveAll(); // save all existing canvases in allcanvases.pdf file
36}
#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:2640
1-D histogram with an int per channel (see TH1 documentation)}
Definition TH1.h:536
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:8854
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3520
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3067
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:2356
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5