Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
_tcanvas.pyzdoc
Go to the documentation of this file.
2
3The TCanvas class is used to create the canvas on which graphical objects such as histograms can be drawn. The following
5
6\code{.py}
7import ROOT
8import numpy
9
10
11def plot():
12 h = ROOT.TH1D("h", "h", 100, -5, 5)
13 h.Fill(numpy.random.normal(size=1000))
14
15 c = ROOT.TCanvas()
16 h.Draw()
17 c.Draw(block=True)
18
19
20if __name__ == "__main__":
21 print("Before plot function")
22 plot()
23 print("After plot function")
25
26Note the optional argument `block` passed to the `Draw` method of the canvas. If set to `True`, it will block the script
27execution and run the ROOT graphics event loop until the <space> key is pressed. This allows interacting with the
28canvas and its content until necessary, then move on with the rest of the script.
29
30Another relevant use case is drawing live updates on a canvas, shown in the example below. In this case, the canvas is
31setup by first creating the object to be drawn and drawing it once. Then, the object is updated in a for loop, which
32could represent for example an incoming stream of data with which the histogram should be filled. Each time the plot
33should be updated, the `ModifiedUpdate` function should be called. This will immediately show the new contents on the
34plot. Finally, the canvas is drawn again with `Draw(block=True)` at the end of the loop so that it stays visible and can
36
37\code{.py}
38import ROOT
39import numpy
40
41
42def live_update():
43 c = ROOT.TCanvas()
44 h = ROOT.TH1D("h", "h", 100, -5, 5)
45
46 h.Draw()
47 for _ in range(100):
49 c.ModifiedUpdate()
51
52if __name__ == "__main__":
53 print("Before plot function")
55 print("After plot function")
57
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter char TVirtualGLPainter plot
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
#define _(A, B)
Definition cfortran.h:108
The Canvas class.
Definition TCanvas.h:23
for(Int_t i=0;i< n;i++)
Definition legend1.C:18
TString as(SEXP s)
Definition RExports.h:87
void Fill(float *output, float value, int size)
const char * True
th1 Draw()