Problem with 2D plot values

I’m sorry, I didn’t see that you replaced

50, 0., 50.,50., 0.,50.

with

50, 0., 0., 50, 0., 0.

Anyway, now I setted

1800, 0., 0., 180, 0., 0.


and I get this plot

I think that the color palette cover the x10^3 (because I’ve it just on y axis but I don’t see it on x axis). is it possible move or re-size the color palette?

Right after c25->cd(1); add gPad->SetRightMargin(0.15);.

Hi @Wile_E_Coyote, thank you. Unfortunately, the color palette doesn’t look like moving…I also tried setting a big number (20). Maybe the best should be to resize it doing it shorter. Is it possible?

Hi @Wile_E_Coyote, thank you…I wrote:

henecdsubstringcutrelTHF->Draw("COLZ"); 
			henecdsubstringcutrelTHF->SetName(heneabname);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TH1 *hh = henecdsubstringcutrelTHF->DrawCopy("colz"); // creates all axes
			TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");
			palette->SetX2NDC(0.93);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			c25->Modified();
			c25->Update();
   			TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);

but it didn’t change.

I guess you need:

gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn

right after “DrawCopy” (i.e. before “GetListOfFunctions”).

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

Hi @Wile_E_Coyote, sorry because I didn’t reply earlier to your last reply in this topic https://root-forum.cern.ch/t/problem-with-2d-plot-values/33142/10 (now it’s close).
Anyway I added

gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn

right after right after “DrawCopy”, I wrote in this way

TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 10000, 0., 0.,10000., 0.,0.);
			TString what = TString::Format("Calo_EnDep[%d] : Calo_EnDep[%d]>> henecdsubstringcutrelTHF", d, c);
			t->Draw(what, cut && cut3sub && cut4sub && !cut5sub && !cut5sub2);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			henecdsubstringcutrelTHF->SetTitle(cdhenecdsubstringcutrelTHFname);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitle(cdeneXnameabenecvsd); 
			henecdsubstringcutrelTHF->GetYaxis()->SetTitle(cdeneYnameabenecvsd);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleSize(c2_YTitleSize);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleFont(c2_YTitleFont);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
			henecdsubstringcutrelTHF->GetYaxis()->SetLabelFont(c2_YLabelFont); 
			henecdsubstringcutrelTHF->GetYaxis()->SetLabelSize(c2_YLabelSize);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleSize(c2_XTitleSize);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleFont(c2_XTitleFont);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
			henecdsubstringcutrelTHF->GetXaxis()->SetLabelFont(c2_XLabelFont); 
			henecdsubstringcutrelTHF->GetXaxis()->SetLabelSize(c2_XLabelSize);
			henecdsubstringcutrelTHF->Draw("COLZ"); 
			henecdsubstringcutrelTHF->SetName(heneabname);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TH1 *hh = henecdsubstringcutrelTHF->DrawCopy("colz"); // creates all axes
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");
			palette->SetX2NDC(0.93);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			c25->Modified();
			c25->Update();
   			TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
   			leghenecdsubstringcutrelTHF->SetHeader("Legend");
			leghenecdsubstringcutrelTHF->SetNColumns(1);
			leghenecdsubstringcutrelTHF->AddEntry(leghenecdsubstringcutrelTHF, "Data", "l");
			leghenecdsubstringcutrelTHF->Draw(); 
			gPad->Update();
			TPaveStats *statsghenecdsubstringcutrelTHF = (TPaveStats*)henecdsubstring

but palette didn’t move…


ROOT Version: 5.34/38
Platform: Windows
Compiler: Not Provided


@couet any recommendation here?

Can you provide some macro I can run ?
The piece of code you posted is not complete.

Hi @couet , in attachment the macro and root file. Don’t worry about the numerical results, because currently I’m doing one other work, so I didn’t set the Initialization parameters for the fit. Just consider the problem about the palette.calo.cpp (941.4 KB)

This is the link to downlaod the root file https://wetransfer.com/downloads/200f00dde023cb4b3ab8d2924be0e9d620190414152629/2e7f3962280cce622d50f1768996d1b920190414152629/23c75c

@faca87 I can run your test. It generates a lot of pdf files. which one should I look at ?

Hi @couet , the plot is si-500636660_ene3-vs-ene2.pdf and you will find it in the folder si-500636660\sub_8-9\sub_3\sub_2

The attached example clearly moves the palette.

calo.C (938.3 KB)

Hi @couet, you code works, but I’m trying to use it also for the second pad then I get error.
In the first pad I’ve

c25->cd(1);
 			TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 10000, 0., 0.,10000., 0.,0.);
			TString what = TString::Format("Calo_EnDep[%d] : Calo_EnDep[%d]>> henecdsubstringcutrelTHF", d, c);
			t->Draw(what, cut && cut3sub && cut4sub && !cut5sub && !cut5sub2);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			henecdsubstringcutrelTHF->SetTitle(cdhenecdsubstringcutrelTHFname);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitle(cdeneXnameabenecvsd);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitle(cdeneYnameabenecvsd);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleSize(c2_YTitleSize);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleFont(c2_YTitleFont);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
			henecdsubstringcutrelTHF->GetYaxis()->SetLabelFont(c2_YLabelFont);
			henecdsubstringcutrelTHF->GetYaxis()->SetLabelSize(c2_YLabelSize);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleSize(c2_XTitleSize);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleFont(c2_XTitleFont);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
			henecdsubstringcutrelTHF->GetXaxis()->SetLabelFont(c2_XLabelFont);
			henecdsubstringcutrelTHF->GetXaxis()->SetLabelSize(c2_XLabelSize);
			henecdsubstringcutrelTHF->Draw("COLZ");
			henecdsubstringcutrelTHF->SetName(heneabname);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TH1 *hh = henecdsubstringcutrelTHF->DrawCopy("colz"); // creates all axes
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
		    TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");
   			palette->SetX1NDC(0.86);
   			palette->SetX2NDC(0.90);
   			palette->SetY1NDC(0.20);
   			palette->SetY2NDC(0.80);
			c25->Modified();
			c25->Update();
   			TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
   			leghenecdsubstringcutrelTHF->SetHeader("Legend");
			leghenecdsubstringcutrelTHF->SetNColumns(1);
			leghenecdsubstringcutrelTHF->AddEntry(hh, "Data", "l");
			leghenecdsubstringcutrelTHF->Draw();
			gPad->Update();
			TPaveStats *statsghenecdsubstringcutrelTHF = (TPaveStats*)hh->GetListOfFunctions()->FindObject("stats");
			statsghenecdsubstringcutrelTHF->SetTextColor(kBlue);
			statsghenecdsubstringcutrelTHF->SetX1NDC(0.80); statsghenecdsubstringcutrelTHF->SetX2NDC(0.98);
			statsghenecdsubstringcutrelTHF->SetY1NDC(0.77); statsghenecdsubstringcutrelTHF->SetY2NDC(0.92);
			gPad->Update();

In the second one I wrote:

	c25->cd(2);
		 	TH2F *henecdsubstringcutrelTHFsumdiff = new TH2F("henecdsubstringcutrelTHFsumdiff", "", 10000, 0., 0., 10000, 0., 0.);
			TString whatsumdiff = TString::Format("(Calo_EnDep[%d] - Calo_EnDep[%d]) : (Calo_EnDep[%d] + Calo_EnDep[%d])>> henecdsubstringcutrelTHFsumdiff", c, d,c,d);
			t->Draw(whatsumdiff, cut && cut3sub && cut4sub && !cut5sub && !cut5sub2);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			henecdsubstringcutrelTHFsumdiff->SetTitle(cdhenecdsubstringcutrelTHFnamesumdiff);
			henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitle(cdeneXnameabenecvsdsumdiff);
			henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitle(cdeneYnameabenecvsdsumdiff);
			henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleSize(c2_YTitleSize);
			henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleFont(c2_YTitleFont);
			henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
			henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetLabelFont(c2_YLabelFont);
			henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetLabelSize(c2_YLabelSize);
			henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleSize(c2_XTitleSize);
			henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleFont(c2_XTitleFont);
			henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
			henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetLabelFont(c2_XLabelFont);
			henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetLabelSize(c2_XLabelSize);
			henecdsubstringcutrelTHFsumdiff->Draw("COLZ");
			henecdsubstringcutrelTHFsumdiff->SetName(heneabname);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TH1 *hh2 = henecdsubstringcutrelTHFsumdiff->DrawCopy("colz"); // creates all axes
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TPaletteAxis * palette2 = (TPaletteAxis *) hh2->GetListOfFunctions()->FindObject("palette");
   			palette2->SetX1NDC(0.86);
   			palette2->SetX2NDC(0.90);
   			palette2->SetY1NDC(0.20);
   			palette2->SetY2NDC(0.80);
			c25->Modified();
			c25->Update();
   			TLegend* leghenecdsubstringcutrelTHFsumdiff = new TLegend(0.65, 0.7, .75, .75);
   			leghenecdsubstringcutrelTHFsumdiff->SetHeader("Legend");
			leghenecdsubstringcutrelTHFsumdiff->SetNColumns(1);
			leghenecdsubstringcutrelTHFsumdiff->AddEntry(hh2, "Data", "l");
			leghenecdsubstringcutrelTHFsumdiff->Draw();
			gPad->Update();
			TPaveStats *statsghenecdsubstringcutrelTHFsumdiff = (TPaveStats*)henecdsubstringcutrelTHFsumdiff->GetListOfFunctions()->FindObject("stats");
			statsghenecdsubstringcutrelTHFsumdiff->SetTextColor(kBlue);
			statsghenecdsubstringcutrelTHFsumdiff->SetX1NDC(0.80); statsghenecdsubstringcutrelTHFsumdiff->SetX2NDC(0.98);
			statsghenecdsubstringcutrelTHFsumdiff->SetY1NDC(0.77); statsghenecdsubstringcutrelTHFsumdiff->SetY2NDC(0.92);
			gPad->Update();
			c25->Print(myplothenecdsubstringcutrelTHF);

but I get this error:

I copied all the code of first pad, just replacing the name:

henecdsubstringcutrelTHF -> henecdsubstringcutrelTHFsumdiff 
hh->hh2
palette->palette2

etc.

calo.C (938.3 KB)

does @couet or someone else know how to fix it please?

I was away for a bit. Looking at your new code now.

I do not get the same error. It seems your code has some invalid pointer:

Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_9:1:
/Users/couet/Downloads/calo.C:6886:14: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
                        p09sub = htemp9sub->GetFunction("gaus")->GetParameter(0);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hi @couet, I don’t know. I get the error just when I add

		TH1 *hh2 = henecdsubstringcutrelTHFsumdiff->DrawCopy("colz"); // creates all axes
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			TPaletteAxis * palette2 = (TPaletteAxis *) hh2->GetListOfFunctions()->FindObject("palette");
   			palette2->SetX1NDC(0.86);
   			palette2->SetX2NDC(0.90);
   			palette2->SetY1NDC(0.20);
   			palette2->SetY2NDC(0.80);
			c45->Modified();
			c45->Update();

otherwise, it works (but I can’t move the palette). Moreover, I would like to increase the marker size…so I wrote:

henecdsubstringcutrelTHFsumdiff->SetMarkerSize(20);

the marker size doesn’t increase.