终端命令在程序运行后自动打开图形

Terminal command to auto open Figures after program run

本文关键字:图形 命令 程序 运行 终端      更新时间:2023-10-16
  • 注意:这是我第一次发帖,对C++编程语言很陌生,所以请耐心等待。
  • 目标: 查找要包含在程序运行后自动打开.png文件(例如:图/pure_comb_4_fits_100logy.png(的宏中的终端命令 OR。
  • 实际结果:终端生成以下消息信息:文件图形/pure_comb_2_fits_100logy.png已创建,然后我需要手动输入打开的数字/pure_comb_2_fits_100logy.png以查看文件。
  • 期望/预期:希望代码自动打开,而无需手动输入终端。如果解决方案是将更多代码添加到 C 文件中,或者只是将语法输入到终端命令中(首选(,则没关系。
  • 代码块:

    void drawpc_4()
    {
    TFile* f4 = TFile::Open("OutputFiles/OutFile_BinaryC_20191011-1551_k4.root");
    TProfile* tp1f_4 = (TProfile*)f4->Get("hmult_recursion_0_2");
    TCanvas* c1 = new TCanvas("c1","");
    tp1f_4->SetMarkerStyle(kFullCircle);
    tp1f_4->SetMarkerColor(kBlack);
    tp1f_4->Draw("ex0p");
    tp1f_4->GetXaxis()->SetRangeUser(0,100);
    tp1f_4->GetXaxis()->SetTitle("Number of particles");
    tp1f_4->GetYaxis()->SetTitle("C_{4}");
    c1->SetLogy();
    c1->SetLogx();                                                                                           
    TF1* fun1 = new TF1("fun1","[0]/pow(x,3)",3.0,99.9);
    fun1->SetParameter(0,6);                                                                                                                                   
    TF1* fun2 = new TF1("fun2","[0]/((x-1)*(x-2)*(x-3))",3.0,99.9);
    fun2->SetParameter(0,6);                                                                                 
    fun2->SetLineColor(kBlue);
    fun1->Draw("same");
    fun2->Draw("same");                                                                                                                  
    TLegend* leg = new TLegend(0.2,0.2,0.46,0.4);
    leg->AddEntry(fun2,"combinatoric function","l");
    leg->AddEntry(fun1,"power law function","l");
    leg->Draw();
    **c1->Print("Figures/pure_comb_4_fits_100logxlogy.png");**
    c1->SetLogx(0);
    TLegend* leg4 = new TLegend(0.48,0.68,0.84,0.88);
    leg4->AddEntry(fun2,"combinatoric function","l");
    leg4->AddEntry(fun1,"power law function","l");
    leg4->Draw();
    delete leg;
    c1->Print("Figures/pure_comb_4_fits_100logy.png");
    delete c1;
    }
    

假设你运行代码

root drawpc_4.C

,我认为您应该考虑运行它

root -l -b -q drawpc_4.C; open Figures/pure_comb_2_fits_100logy.png

相反。这将在执行完drawpc_4.C后立即打开您的png文件。