Hello,
I am trying to add a background image with a Highlight connection plot, is this possible or not?
If it is possible, how do I do it?
In my case, I write my macro as the example “hlquantiles.C”, and I can’t find how to refresh the plot without losing the background image.
Thank you in advance for your help.
Does it look like you already have an example of what you call a “background image” can you post it? so we can understand what you mean exactly bat “background image”.
Hi,
You can see a example of the code I try :
/// \file
/// \ingroup tutorial_math
/// Demo for quantiles (with highlight mode)
///
/// \macro_image
/// \macro_code
///
/// \authors Rene Brun, Eddy Offermann, Jan Musinsky
TList *lq = 0;
TGraph *gr = 0;
void hlquantiles() {
const Int_t nq = 100;
const Int_t nshots = 10;
Double_t xq[nq]; // position where to compute the quantiles in [0,1]
Double_t yq[nq]; // array to contain the quantiles
for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq;
TGraph *gr70 = new TGraph(nshots);
TGraph *gr90 = new TGraph(nshots);
TGraph *gr98 = new TGraph(nshots);
TGraph *grq[nq];
for (Int_t ig = 0; ig < nq; ig++) grq[ig] = new TGraph(nshots);
TH1F *h = new TH1F("h","demo quantiles",50,-3,3);
for (Int_t shot=0;shot<nshots;shot++) {
h->FillRandom("gaus",50);
h->GetQuantiles(nq,yq,xq);
gr70->SetPoint(shot,shot+1,yq[70]);
gr90->SetPoint(shot,shot+1,yq[90]);
gr98->SetPoint(shot,shot+1,yq[98]);
for (Int_t ig = 0; ig < nq; ig++)
grq[ig]->SetPoint(shot,shot+1,yq[ig]);
}
gr98->SetMarkerStyle(22);
gr98->SetMarkerColor(kRed);
gr90->SetMarkerStyle(21);
gr90->SetMarkerColor(kBlue);
gr70->SetMarkerStyle(20);
gr70->SetMarkerColor(kMagenta);
auto mg = new TMultiGraph("mg","mg");
mg->Add(gr70);
mg->Add(gr90);
mg->Add(gr98);
//show the original histogram in the top pad
TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900);
c1->SetFillColor(41);
c1->Divide(1,3);
c1->cd(1);
h->SetFillColor(38);
h->Draw();
// show the final quantiles in the middle pad
c1->cd(2);
gPad->SetFrameFillColor(33);
gPad->SetGrid();
gr = new TGraph(nq,xq,yq);
gr->SetTitle("final quantiles");
gr->SetMarkerStyle(21);
gr->SetMarkerColor(kRed);
gr->SetMarkerSize(0.3);
gr->Draw("ap");
// prepare quantiles
TImage *back = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
// back->Draw();
lq = new TList();
for (Int_t ig = 0; ig < nq; ig++) {
grq[ig]->SetMinimum(gr->GetYaxis()->GetXmin());
grq[ig]->SetMaximum(gr->GetYaxis()->GetXmax());
grq[ig]->SetMarkerStyle(23);
grq[ig]->SetMarkerColor(ig%100);
grq[ig]->SetTitle(TString::Format("q%02d", ig));
lq->Add(grq[ig]);
}
lq->Add(back);
TText *info = new TText(0.1, 2.4, "please move the mouse over the graph");
info->SetTextSize(0.08);
info->SetTextColor(gr->GetMarkerColor());
info->SetBit(kCannotPick);
info->Draw();
gr->SetHighlight();
c1->HighlightConnect("HighlightQuantile(TVirtualPad*,TObject*,Int_t,Int_t)");
// show the evolution of some quantiles in the bottom pad
c1->cd(3);
TPad *pad1 = new TPad("pad1","",0,0,1,1);
TPad *pad2 = new TPad("pad2","",0,0,1,1);
pad2->SetFillStyle(4000); //will be transparent
pad1->Draw();
pad1->cd();
back->Draw("x");
pad1->Modified();
// pad1->Update();
c1->cd(3);
pad2->Draw();
pad2->cd();
// gPad->DrawFrame(0,0,nshots+1,3.2);
mg->Draw("ALP");
gPad->SetGrid();
pad2->Update();
// add a legend
TLegend *legend = new TLegend(0.85,0.74,0.95,0.95);
legend->SetTextFont(72);
legend->SetTextSize(0.05);
legend->AddEntry(gr98," q98","lp");
legend->AddEntry(gr90," q90","lp");
legend->AddEntry(gr70," q70","lp");
legend->Draw();
}
void HighlightQuantile(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
{
// show the evolution of all quantiles in the bottom pad
if (obj != gr) return;
if (ihp == -1) return;
TVirtualPad *savepad = gPad;
pad->GetCanvas()->cd(3);
// pad->GetPad(1)->cd();
// pad->GetPad()->cd();
// lq->At(100)->Draw("x");
// TPad subpad2 = (TPad)pad->GetPad(2);
lq->At(ihp)->Draw("alp same");
gPad->Update();
savepad->cd();
}
Hi,
I found a solution to my trouble :
/// \file
/// \ingroup tutorial_math
/// Demo for quantiles (with highlight mode)
///
/// \macro_image
/// \macro_code
///
/// \authors Rene Brun, Eddy Offermann, Jan Musinsky
TList *lq = 0;
TGraph *gr = 0;
TPad *pad1 = 0;
TPad *pad2 = 0;
void hlquantiles() {
const Int_t nq = 100;
const Int_t nshots = 10;
Double_t xq[nq]; // position where to compute the quantiles in [0,1]
Double_t yq[nq]; // array to contain the quantiles
for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq;
TGraph *gr70 = new TGraph(nshots);
TGraph *gr90 = new TGraph(nshots);
TGraph *gr98 = new TGraph(nshots);
TGraph *grq[nq];
for (Int_t ig = 0; ig < nq; ig++) grq[ig] = new TGraph(nshots);
TH1F *h = new TH1F("h","demo quantiles",50,-3,3);
for (Int_t shot=0;shot<nshots;shot++) {
h->FillRandom("gaus",50);
h->GetQuantiles(nq,yq,xq);
gr70->SetPoint(shot,shot+1,yq[70]);
gr90->SetPoint(shot,shot+1,yq[90]);
gr98->SetPoint(shot,shot+1,yq[98]);
for (Int_t ig = 0; ig < nq; ig++)
grq[ig]->SetPoint(shot,shot+1,yq[ig]);
}
gr98->SetMarkerStyle(22);
gr98->SetMarkerColor(kRed);
gr90->SetMarkerStyle(21);
gr90->SetMarkerColor(kBlue);
gr70->SetMarkerStyle(20);
gr70->SetMarkerColor(kMagenta);
auto mg = new TMultiGraph("mg","mg");
mg->Add(gr70);
mg->Add(gr90);
mg->Add(gr98);
//show the original histogram in the top pad
TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900);
c1->SetFillColor(41);
c1->Divide(1,3);
c1->cd(1);
h->SetFillColor(38);
h->Draw();
// show the final quantiles in the middle pad
c1->cd(2);
gPad->SetFrameFillColor(33);
gPad->SetGrid();
gr = new TGraph(nq,xq,yq);
gr->SetTitle("final quantiles");
gr->SetMarkerStyle(21);
gr->SetMarkerColor(kRed);
gr->SetMarkerSize(0.3);
gr->Draw("ap");
// prepare quantiles
TImage *back = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
// back->Draw();
lq = new TList();
for (Int_t ig = 0; ig < nq; ig++) {
grq[ig]->SetMinimum(gr->GetYaxis()->GetXmin());
grq[ig]->SetMaximum(gr->GetYaxis()->GetXmax());
grq[ig]->SetMarkerStyle(23);
grq[ig]->SetMarkerColor(ig%100);
grq[ig]->SetTitle(TString::Format("q%02d", ig));
lq->Add(grq[ig]);
}
lq->Add(back);
TText *info = new TText(0.1, 2.4, "please move the mouse over the graph");
info->SetTextSize(0.08);
info->SetTextColor(gr->GetMarkerColor());
info->SetBit(kCannotPick);
info->Draw();
gr->SetHighlight();
c1->HighlightConnect("HighlightQuantile(TVirtualPad*,TObject*,Int_t,Int_t)");
// show the evolution of some quantiles in the bottom pad
c1->cd(3);
pad1 = new TPad("pad1","",0,0,1,1);
pad2 = new TPad("pad2","",0,0,1,1);
pad2->SetFillStyle(4000); //will be transparent
pad1->Draw();
pad1->cd();
back->Draw("x");
pad1->Modified();
c1->cd(3);
pad2->SetFillStyle(4000);
pad2->SetFrameFillStyle(4000);
pad2->Draw();
pad2->cd();
mg->Draw("ALP");
gPad->SetGrid();
pad2->Update();
// add a legend
TLegend *legend = new TLegend(0.85,0.74,0.95,0.95);
legend->SetTextFont(72);
legend->SetTextSize(0.05);
legend->AddEntry(gr98," q98","lp");
legend->AddEntry(gr90," q90","lp");
legend->AddEntry(gr70," q70","lp");
legend->Draw();
}
void HighlightQuantile(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
{
// show the evolution of all quantiles in the bottom pad
if (obj != gr) return;
if (ihp == -1) return;
TVirtualPad *savepad = gPad;
pad->GetCanvas()->cd(3);
pad1->cd();
lq->At(100)->Draw("x");
pad2->SetFillStyle(4000);
pad2->SetFrameFillStyle(4000);
pad2->Draw();
pad2->cd();
lq->At(ihp)->Draw("alp");
gPad->Update();
savepad->cd();
}
It is not the most elegant way, but it works.