Hello,
I have been trying to write an individualized title for each of my stats boxes. I have tried to use TLists, as shown in the TPaveStats “statistics box editing” example ( root.cern.ch/root/html/TPaveStats.html#PS03 ). Unlike that example, I’m using a TGraph and having some serious issues. I suppose I could go in and add a TPaveText above each stats box, but in my real work I’m plotting over half a dozen fits - having a title seems like a reasonable approach. Any help would be most appreciated.
Below I will post some sample code with dummy variables to illustrate my method.
With much thanks,
Josh Magee
The following “short, self contained, correct” example macro compiles in root:
root[0] .L test_function.C++g"
root[1] test_function()
This produces the dummy plot but the stats box doesn’t include the “title”.
//ROOT based libraries
#include <TROOT.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TGraph.h>
#include <TList.h>
#include <TF1.h>
#include <TPaveStats.h>
void test_function(void) {
gROOT->Reset();
gROOT->SetStyle("Modern");
gStyle->SetOptFit(1111);
const int n = 3;
const float x_values[n] = {1,2,3}; //independent variable
const float y_values[n] = {3,4,5}; //dependent variable
TGraph *graph = new TGraph(n,x_values,y_values);
TCanvas *canvas = new TCanvas("canvas","title");
graph->Draw("ap");
canvas->Modified();
canvas->Update();
TF1 *fFit = new TF1("fFit","pol1");
graph->Fit("fFit","sames");
canvas->Modified();
canvas->Update();
TList *list;
TPaveStats *stats = (TPaveStats*) graph->GetListOfFunctions()->FindObject("stats");
if (stats) { //check to make sure *stats isn't null
stats->SetTextColor(kBlue);
TList *list = stats->GetListOfLines();
TText *title_line = new TText(0,0,"Stats Box Title");
list->AddFirst(title_line); //add new line to top of stats box ??
stats->Draw("sames");
}
canvas->Modified();
canvas->Update();
} //conclude example macro