Gray axis or dot-like Grid

Dears
I know that this issue was posted many times,
but the solution not works with me
I have a canvas c1, and create all options I need for histogram drawings
at the end of the Script I added

c1->SetGrid();

histo1->GetXaxis()->SetAxisColor(17);
histo1->GetYaxis()->SetAxisColor(17);
c1->RedrawAxis();
c1->RedrawAxis(“g”);
c1->RedrawAxis();

But this still show me a gray axis,

any solutions, or if I can make a dot-like grid would be better ?

Thanks

Can you post a running script reproducing this problem ?

TFile *file_input1 = new TFile("input.root","read");
 TFile* file_output = TFile::Open("data.root", "RECREATE");  // my output file
 c1 = new TCanvas("c1", "c1",800,500);
TH1F * histo1=(TH1F*)file_input1->Get("Sum");

gStyle->SetOptStat(0);
 gROOT->ForceStyle();

 histo1->SetXTitle("Gamma Energy [keV]");
     histo1-> GetXaxis() -> CenterTitle();
    histo1->SetYTitle("Counts");
    histo1-> GetYaxis() -> CenterTitle();
     histo1->Draw("");
    
    TAxis *Xaxis = histo1->GetXaxis();
    Xaxis->SetLabelOffset(0.005);
    Xaxis->SetLabelSize(0.03);
    Xaxis->SetTickLength( 0.03);
   Xaxis->SetTitleOffset(1);
   Xaxis->SetTitleSize(0.035);
    
    
    TAxis *Yaxis = histo1->GetYaxis();
   Yaxis->SetLabelOffset(0.005);
   Yaxis->SetLabelSize(0.03);
    Yaxis->SetTickLength( 0.03);
   Yaxis->SetTitleOffset(1.3);
   Yaxis->SetTitleSize(0.035);
    
     c1->SetGrid();
   
   histo1->GetXaxis()->SetAxisColor(17);
   histo1->GetYaxis()->SetAxisColor(17);
   c1->RedrawAxis();
     c1->RedrawAxis("g");
     c1->RedrawAxis();

Why do you call RedrawAxis ? it is not needed as you draw only on histogram. No extra drawing will obscur the axis. Appart from that i do not see anything wrong in you macro.
I do not know which style will be applied by ForceStyle, but it should be fine. The axis should be gray as you asked them to be grey (SetAxisColor(17) )

my issue is that if I draw the grid by using (c1->SetGrid(); )
the grid will be black, and I need it gray
Rene in previous post suggest to change the color of the axis to gray, plot the grid then re-draw the axis
this solution I included here, but it is not working

My goal is to get a black axis and gray grid (Or dot like grid), How can I achieve this please?

Many thanks

The grid is dotted by default … you see solid lines for the grid ?

Yes, solid black line

With the following code:

{
   TCanvas *c1 = new TCanvas("c1","c1");
   c1->SetGrid();
   TH2C *h = new TH2C("h","h",32,0.,32.,64,0.,64.);
   h->SetStats(0);
   h->Draw();
}

I see:

Do you see the same ?

Thank you for helping,
yes I still getting solid black line.
so I suppose it is root issue, I am using root v5.34

start root with the option -n ( root -n) and execute again the few lines I sent you . is the grid still solid ?

Yes, lines are still solid

Then it must be a problem with the ROOT version … I am not aware of a such problem in any old ROOT version. On which machine are you using ROOT ?

Hello
I am using ubuntu 16.04

I just ran the macro I sent you with 5.34 and It is fine for me … I see the dotted lines.

Seems to me either your machine is in a weird state or you have some setting (in your rootlogon.C ?) changing the grid line style… but ‘root -n’ should have bypassed such setting. As we said off-line it would be good you try the macro I sent you on an other machine.

Hi Olivier,

May be it is the same problem, that was fixed in ROOT6?
As you remember, on new libX11 zero line width does not work properly with dashed line styles.

Regards,
Sergey

In that case setting the grid line width bigger than 1 (2 for instance) should make the dotted line reappear . @Noor1 could you try that ?

I tried the macro you send, and the macro I wrote on another machine and I got the default (dot-like) grid,

Now I changed the grid line width (c1->SetGrid(2.);), and still got the solid line style.

So it doesn’t seems to be the issue @linev mentioned…

I must admit I do not have more ideas right now … what do you get when you save the image in a pdf file ?

Probably, one should use gStyle to change grid settings:

gStyle->SetGridStyle(3);
gStyle->SetGridWidth(3);