Log scale of Multigraph


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


Dear All,
I am trying to plot a multi graph,
I start first with single graph, I plot the data file
auto gr1 = new TGraph(“energy_loss_electronic.dat”);
gr1->SetLineColor(kBlue-2);
gr1->SetMarkerStyle(7);
gr1->SetMarkerColor(kBlue-2);
gr1->SetMarkerSize(0.6);
gr1->Draw(“APL”);

after plotting the graph I took the log scale for x-axis using the Editor windows,
both the graph and the log scal are attached as (gr1 &gr1_log)

and because I am aiming to plot two graphs , I imposed the multigraph

    auto mg = new TMultiGraph();
auto gr1 = new TGraph("energy_loss_electronic.dat");
    mg->Add(gr1);
    mg->Draw("APL");

then I start to get strange values less than zero, and the log scale is not logic, I have attached the new graphs (mg &mg_log)

what is the difference between single graph and muligraph, when I edit the x-axis scale to log ? and How can overcome this issue

thanks

Can you provide a small macro building the multigraph you have problems with ?

mg.pdf (18.3 KB)
mg_log.pdf (14.9 KB)
gr1.pdf (18.3 KB)
gr1_log.pdf (19.9 KB)graph.C (1.1 KB)

The two .dat files are missing.

energy_loss_electronic.txt (2.5 KB)
energy_loss_nuclear.txt (2.5 KB)

Due to uploading issues, I converted them to .txt

void graph()
{

   auto mg  = new TMultiGraph();
   auto gr1 = new TGraph("energy_loss_electronic.txt");
   auto gr2 = new TGraph("energy_loss_nuclear.txt");

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

   gr1->SetLineColor(kBlue-2);
   gr1->SetMarkerStyle(7);
   gr1->SetMarkerColor(kBlue-2);
   gr1->SetMarkerSize(0.6);

   gr2->SetMarkerStyle(21);
   gr2->SetMarkerColor(46);
   gr2->SetMarkerSize(0.5);

   mg->Add(gr1);
   mg->Add(gr2);

   auto axis = mg->GetXaxis();

   axis->SetLimits(0.0001,10000000);

   mg->Draw("apl");

   gPad->SetLogx();
}

Thank you for helping, and I can see that it works with your macro perfectly. but if I tried to compile it , it give me Error
axis-> SetLimits(0.0,10000000); … illegal pointer to class object GetXaxis(),

I tried previously this option by using
mg->GetXaxis()-> SetLimits(0,10000000);
mg->GetYaxis()-> SetLimits(0,4);
but also did not work

can I know what is the explanation for obtaining values less than zero in case of multigraph??

if you compile you need to add the relevant include files:

#include "TCanvas.h"
#include "TMultiGraph.h"
#include "TGraph.h"
#include "TAxis.h"

Log(0) is invalid.

Thank you for all explanation and assistance.

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