Hi all,
I do the TH2C histogram that is in attach.
Now the numbers on Y axis are too many, I want 0, 4, 8,… but I want the grid for every number (0,1,2,3,4…).
How should I do?
I use, for the grid, the code:
TCanvas *c1 = new TCanvas("c1","Visualizzazione",10,10,1000,500);
c1->SetGrid();
TH2C *h100 = new TH2C("h100","Visualizzazione",32,0.,32.,64,0.,64.);
h100->GetXaxis()->SetNdivisions(32);
h100->GetYaxis()->SetNdivisions(64);
That quite simple. The code whcih draw the grid is:
TPad *grid = new TPad("grid","",0,0,1,1);
grid->Draw();
grid->cd();
grid->SetGrid();
grid->SetFillStyle(4000);
TH2 *hgrid = new TH2C("hgrid","",32,0.,32.,64,0.,64.);
hgrid->Draw();
hgrid->GetXaxis()->SetNdivisions(32);
hgrid->GetYaxis()->SetNdivisions(64);
hgrid->GetYaxis()->SetLabelOffset(999.);
hgrid->GetXaxis()->SetLabelOffset(999.);
It should be put after all the histogram drawings. And the histograms should be drawn without grid. This code you can even put in a function PaintGrid() and call it after all the histogram drawings.
[quote=“couet”]That quite simple. The code whcih draw the grid is:
TPad *grid = new TPad("grid","",0,0,1,1);
grid->Draw();
grid->cd();
grid->SetGrid();
grid->SetFillStyle(4000);
TH2 *hgrid = new TH2C("hgrid","",32,0.,32.,64,0.,64.);
hgrid->Draw();
hgrid->GetXaxis()->SetNdivisions(32);
hgrid->GetYaxis()->SetNdivisions(64);
hgrid->GetYaxis()->SetLabelOffset(999.);
hgrid->GetXaxis()->SetLabelOffset(999.);
It should be put after all the histogram drawings. And the histograms should be drawn without grid. This code you can even put in a function PaintGrid() and call it after all the histogram drawings.[/quote]
Why have you added the option SAME in two places ? that was not what I sent you.
O,k if at some point you end up with something I can run, I will look at it.
Hi couet,
my apologies for the delayed response.
I send you a simple example.
{
TCanvas *c1 = new TCanvas("c1","Visualizzazione",10,10,1000,500);
gStyle->SetOptStat(0);
TH2C *h100 = new TH2C("h100","Visualizzazione",32,0.,32.,64,0.,64.);
for (int i=0; i<64; i++)
{
h100->Fill(25,i,1);
}
h100->GetXaxis()->SetNdivisions(32);
h100->GetYaxis()->SetNdivisions(16);
h100->SetFillColor(3);
// h100->Draw("BOX");
TPad *grid = new TPad("grid","",0,0,1,1);
grid->Draw();
grid->cd();
grid->SetGrid();
grid->SetFillStyle(4000);
TH2 *hgrid = new TH2C("hgrid","",32,0.,32.,64,0.,64.);
hgrid->Draw();
hgrid->GetXaxis()->SetNdivisions(32);
hgrid->GetYaxis()->SetNdivisions(64);
hgrid->GetYaxis()->SetLabelOffset(999.);
hgrid->GetXaxis()->SetLabelOffset(999.);
h100->Draw("BOX");
}
If I write h100->Draw("BOX"); after h100->SetFillColor(3); I obtain only the grid, like figure c1.gif,
if I write where it is now, I obtain the figure prova1.jpg.
Why?
I would the figure prova1.jpg with grid of figure c1.gif.