Home | News | Documentation | Download

How do I change the title of my plot?


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/00
Platform: Ubuntu WSL2
Compiler: gedit, nano.


Hello, I’m new to ROOT. I’m trying to change the title, xlabel and ylabel of my plot. My data is loaded from a .root file, see below.

#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TH1F.h"
#include <iostream>

using namespace std;


void kinetic_energy_vs_position_z(){

	TFile * f = new TFile("Myfile.root");
	TTree *T = (TTree *) f->Get("output_DATA");
	T -> Draw("kinetic_energy" );
}

How do I change the title of my plot and also the x and y label?
Is it possible to make my graph “smoother” ?

Thanks

Hi,

by default your histogram is called htemp, so doing

TH1 * myh = static_cast<TH1*>(gPad->GetPrimitive("htemp"));

will get you the pointer of your histogram. Then you can change its title with

myh->SetTitle("New title");

and the X and Y axis titles with

myh->GetXaxis()->SetTitle("New X-axis title");
myh->GetYaxis()->SetTitle("New Y-axis title");

Thanks now it worked