First Steps: Canvases and Pads
Creating TCanvas and TPad objects. Making a TPad the current pad. Adding
objects to the current pad. Updating pads.
Start by reading about
in the ROOT Crib. Now we will put it into practice. You may find it
helpful to open a second browser window looking at the TCanvas
documentation as we proceed.
Run ROOT and create a TCanvas:-
TCanvas *my_canvas = new TCanvas("my_canvas","Plotting Canvas",150,10,990,660);
A window with the title "Plotting Canvas" should appear. Now divide the
canvas into 6 pads:-
To show that we now have 6 pads get CINT to find one with:-
Make pad my_canvas_3 the current pad and create a 2D histogram in it (we
will look at histogram in the Histograms lesson)
and add it to the current pad:-
TH1F *hist = new TH1F("hist","My histogram",100,0.,100.);
This produces an empty histogram in the current pad. If running compiled
code we would now have to:-
but thanks to a
this has been done automatically. Now we update the histogram:-
Although this updates the histogram, the pad does not change
as it is unaware that the histogram has changed. To tell it we have to:-
For another simple example of TCanvas use see the ROOT tutorial
An Example of Object Oriented User Interface
- The basic graphics window is a
that inherits from a
- A TCanvas can be divided into a rectangular grid of TPads using its
- Any Tpad can be made the current using its cd() message.
- Sending objects that can draw themselves their Draw() message adds
them to the current pad.
- After updating objects in a pad it is necessary to inform the pad using
its Modified() message.
- A TCanvas or TPad is not redrawn until its Update() message is sent,
although this is done automatically in interactive sessions.
Go Back to the
The First Steps Top Page
If you have any comments about this page please send them to