DrawFrame is ignored

Good afternoon!

This is my sample code:

void function_1(){ 
    int i;
    
    double x[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0};
    int n = (int)(sizeof(x) / sizeof(double));
    for (i = 0; i < n; i++)
        x[i] /= 3.0;
    
    double y[] = {86.25, 85.2, 73.4, 75.3, 71.4, 68.4, 73.35, 64.4, 83.15, 68.4, 50.65};
    
    double dy[] = {95.33, 94.35, 81.95, 83.77, 79.76, 76.63, 81.98, 72.54, 92.33, 76.69, 57.55};
    for (i = 0; i < n; i++)
        dy[i] -= y[i];
    
    TGraphErrors *gr = new TGraphErrors(n, x, y, NULL, dy);
    
    //===  Plots ===================================
    
    TCanvas *c1 = new TCanvas("c1", "c1", 2000, 1500);
    
    c1->DrawFrame(0.0, 0.0, 4.0, 100.0);
    
    gr->Draw("AP");
    //c1->DrawFrame(0.0, 0.0, 4.0, 100.0);
    
    //----------------------------------------------
    
    c1->SaveAs("result.pdf");
    
    delete c1;
    
    //=== /Plots ===================================
    
    delete gr;
}

Here DrawFrame line doesn’t affect anything. If I put it after gr->Draw("AP"), only frame is drawn, without points. I would like to obtain both frame and points.

Help me with this, please.

Best regards,
Natalia

My system:

> lsb_release -d && uname -r
No LSB modules are available.
Description:    Debian GNU/Linux 12 (bookworm)
6.3.0-2-amd64

> g++ --version
g++ (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> root --version
ROOT Version: 6.28/04
Built for linuxx8664gcc on May 08 2023, 02:44:07
From tags/v6-28-04@v6-28-04

Hi @Natalia_D ,

Based on your code, can you try adding:

    c1->Update();
    c1->Modified();

after calling Draw on your TGraph and before saving the pdf. This should give you the frame along with the points.

Best,
Aaron

Actually, code works for me without changes - with ROOT 6.32
But one probably can add c1->Modified(); c1->Update(); before crating PDF file.

Added. Nothing has changed…

If you are using DrawFrame method you probably want to draw TGraph only with gr->Draw("P"). Because A draw option redraw frame axes again.

Do you see axes drawn when just do c1->DrawFrame() without drawing TGraph?

Nevertheless your macro works for me - both with 6.28, 6.32 and master branch of ROOT.

Yes! I have removed “A” and it works!

Thank you!

void function_1(){
    int i;

   double x[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0};
   int n = (int)(sizeof(x) / sizeof(double));
   for (i = 0; i < n; i++) x[i] /= 3.0;
   
   double y[] = {86.25, 85.2, 73.4, 75.3, 71.4, 68.4, 73.35, 64.4, 83.15, 68.4, 50.65};
   double dy[] = {95.33, 94.35, 81.95, 83.77, 79.76, 76.63, 81.98, 72.54, 92.33, 76.69, 57.55};
   
   for (i = 0; i < n; i++) dy[i] -= y[i];
   
   auto gr = new TGraphErrors(n, x, y, NULL, dy);
   gr->SetMarkerStyle(20);
   gr->SetMarkerColor(kRed);
   
   //===  Plots ===================================
   
   auto c1 = new TCanvas("c1", "c1", 2000, 1500);
   
   c1->DrawFrame(0.0, 0.0, 4.0, 100.0);
   gr->Draw("PL");
   
   c1->SaveAs("result.pdf");
}