Home | News | Documentation | Download

Canvas not saving updated version in Batch mode

Hi.
I’ve been trying to build a program to simulate a Particle in Cell model. It produces 4 canvases with one graph each, and the user has the option to not want to see them. If he first chooses to see them and the not to, the canvas should stay frozen while the rest of the program runs. The program can also save the graphs, and even though the canvas is frozen, is the user chooses to save, the saved file should be updated. For that I’ve been using gRoot->SetBatch(). When I save the images in a .eps file it works fine but in .jpg or .png it doesn’t update and just keeps resaving the same image.
Is there something that needs to be done differently in order to save with jpg?
Bellow is a copy of the relevant part of code

    CDensity->SetBatch(kTRUE);
    string time1 = to_string(Time);
    time1 = time1.substr(0, time1.find(".")+3);
    string name = "../Density_"+time1+".jpg";
    string title = "Density at "+time1;
    CDensity->SetTitle(title.c_str());
    GDensity->SetTitle(title.c_str());

    GDensity->Draw("AP");
  

    if(show_plot){

      CDensity->SetBatch(kFALSE);
      CDensity->cd();
      CDensity->Update();
      gSystem->ProcessEvents();
    }

    if(save_plot){
      CDensity->Update();
      CDensity->SaveAs(name.c_str());
      gSystem->ProcessEvents();
    }

     gSystem->ProcessEvents();

Above, CDensity is the TCanvas and GDensity is the TGraph
Thanks

Hi,

@couet probably knows the answer. Let’s wait until next week.

In principal it should work the same way with eps png and jpeg.
Can you provide a small macro we can run reproducing your problem ?