Legend font and graph size

I am trying to plot three graphs on the same Canvas.
it works, but I have two issues.
one is that the legend font is not changing I dont need it to be italic.
and the Xaxis title is below the border???
How can I fix these issues

void graph1()
{
    TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",0,0,700,300);
    c1->SetGrid();
    auto mg  = new TMultiGraph();
    auto gr1 = new TGraph("energy_loss_electronic1.txt");
    auto gr2 = new TGraph("energy_loss_nuclear1.txt");
    auto gr3 = new TGraph("energy_loss1.txt");


    //gr1->SetName("g");
    //gr1->SetTitle("g");
    // gr1->SetFillColorAlpha(42,0);

    gr3->SetLineColor(kBlue+2);
    gr3->SetMarkerStyle(1);
    gr3->SetMarkerColor(kBlue+2);
    gr3->SetMarkerSize(0.1);
    
    gr2->SetLineColor(kRed+2);
    gr2->SetMarkerStyle(1);
    gr2->SetMarkerColor(kRed+2);
    gr2->SetMarkerSize(0.1);
   
    gr1->SetLineColor(kGreen+2);
    gr1->SetMarkerStyle(1);
    gr1->SetMarkerColor(kGreen+2);
    gr1->SetMarkerSize(0.1);

    mg->Add(gr1);
    mg->Add(gr2);
    mg->Add(gr3);
   
    mg->Draw("APL");
    auto Xaxis = mg->GetXaxis();
    Xaxis->SetLimits(1000,1000000000);
    Xaxis->SetTitle("Alpha Energy [eV]");
    Xaxis->CenterTitle();
    Xaxis->SetTitleSize(0.06);
    Xaxis->SetTitleOffset(0.9);
    Xaxis->SetTickLength(0.02);
    Xaxis->SetLabelSize(0.04);
    Xaxis->SetLabelOffset(0.005);

  // Xaxis->Scale(1000);

 
   auto Yaxis = mg->GetYaxis();
    Yaxis->SetTitle("Stopping Power [keV/#mum]");
    Yaxis->CenterTitle();
    Yaxis->SetTitleSize(0.06);
    Yaxis->SetTitleOffset(0.8);
    Yaxis->SetTickLength(0.02);
    Yaxis->SetLabelSize(0.04);
    Yaxis->SetLabelOffset(0.005);


   gPad->SetLogx();
   
   
   TLegend *leg=new TLegend(0.88,0.63,0.6,0.87);
   leg->AddEntry(gr1,"Electronic Stopping Power","l");
   leg->AddEntry(gr2,"Nuclear Stopping Power","l");
   leg->AddEntry(gr3,"Total Stopping Power","l");
   leg->SetTextFont(12);
   //leg->SetHeader("Legend");
   
   leg->Draw();
   
   
   
   
}

test.pdf (50.5 KB)

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


  1. You asked for Italic font. Font 12 is italic
  2. You can increase the bottom margin of the plot t change the title offset.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.