Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
_thistpainter.pyzdoc
Go to the documentation of this file.
1\pythondoc THistPainter
2
3### Keeping the canvas open after drawing in Python
4- If the call to TH1.Draw is a top-level statement (i.e. the histogram remains in scope at the end of the script), e.g.
5\code{.py}
6# short example makeAndDrawHisto.py: initialize a histogram and draw it on a canvas
7test_histo = ROOT.TH1D("test_histo", "Histogram to draw", 200, -5, 5)
8test_histo.FillRandom("gaus", 1000)
9test_canvas = ROOT.TCanvas("test_canv", "test_canv", 900, 700)
10test_histo.Draw()
11\endcode
12It is sufficient to call Python with the flag `-i` to keep the TBrowser open:
13\code{.sh}
14# -i flag keeps the TBrowser open with the TCanvas on it
15python -i makeAndDrawHisto.py
16\endcode
17
18- If the call to TH1.Draw is not at top-level, both the TCanvas and TH1 objects need to remain in scope. One way to accomplish this is with ROOT.SetOwnership, as in this example:
19\code{.py}
20# contents of short example makeAndDrawHistoInMain.py:
21def main():
22 '''
23 Initialize a histogram and draw it in a non-top level function, using ROOT.SetOwnership to keep the canvas and histogram open after execution
24 '''
25 test_histo = ROOT.TH1D("test_histo", "Histogram to draw", 200, -5, 5)
26 test_histo.FillRandom("gaus", 1000)
27
28 test_canv = ROOT.TCanvas("test_canv", "test_canv", 900, 700)
29 ROOT.SetOwnership(test_canv, False)
30 ROOT.SetOwnership(test_histo, False)
31 test_canv.SaveAs("myDrawExample.png")
32
33if __name__ == '__main__':
34 main()
35\endcode
36To keep the TBrowser open, the Python script should be run with the `-i` flag:
37\code{.sh}
38python -i makeAndDrawHistoInMain.py
39\endcode
40
41\endpythondoc
int main()
Definition Prototype.cxx:12
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:693
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
The histogram painter class.
h1 FillRandom("gaus", 30000)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TString as(SEXP s)
Definition RExports.h:86
const char * False