Set title in plot having only canvas

I am reproducing the example plot of the voltage from the examples of garfield++ pf ´RPCbyneBEM.C´, but I am only retrieving the canvas from the variable and seting the title of the canvas, But how do I save the image of the plot and adding the title ? Do I need to reconstruct the plot in a ´TGraph´ class variable

Here is the code I am using to save the image in ´png´ format. I am only able to retrieve the canvas beacuse ´GetCanvas()´ is defined in ´ViewBase.hh´.

ViewField fieldViewPot; 
fieldViewPot.SetArea(-10, -10, -1, 10, 10, 2); 
fieldViewPot.SetPlane(0, 0, 1, 0, 0, z);

@hschindl should know how to retrieve the TGraph.

apologies for my late reply. Setting the canvas title (text in the title bar of the window) and saving the canvas to file should indeed work the way you did it in this snippet of code.

If you want to set and show the title of the TF2 function (which is the object used for drawing the contour plot) you could do something like this:

auto f2 = (TF2*)gROOT->FindObject("f2D_0");
if (!f2) {
  std::cerr << "Didn't find f2D_0\n";
  return 0;

If you want to save the plot to a ROOT file (not sure if this is what you had in mind), something like this should work:

auto f2 = (TF2*)gROOT->FindObject("f2D_0");
if (!f2) {
  std::cerr << "Didn't find f2D_0\n";
  return 0;
auto h2 = f2->GetHistogram();
if (!h2) {
  std::cerr << "Histogram does not exist.\n";
  return 0;
TFile outfile("rpc.root", "RECREATE");

Thanks, it worked. How it is supposed to work with 3D, with TF3 ? in case of plotting the 3D Geometry. How do come to finding “f2D_0” object ?

To save the 3D geometry to a file, you can do something like this

ViewGeometry geomView3d;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.