Hello,
to do a “simple” x:y plot of some data (read into a tree) I use TGraph. This works fine, but I want to reverse the x-axis. I can already reverse the direction, but I want as well that TGraph draws the plot from higher x-values to lower x-values. How does this work?
My code looks like this:
#include <TTree.h>
#include <TCanvas.h>
#include <TPad.h>
#include <TFile.h>
#include <TGraph.h>
#include <TGaxis.h>
void graph() {
// save as root file
TFile* file = new TFile("data07.root", "RECREATE");
file->cd();
// create Canvas
gROOT->SetStyle("Plain");
TCanvas *c1 = new TCanvas("c1","");
// read data in tree
TTree *tree = new TTree("data","");
tree->ReadFile("data.txt","TC:L");
int size = tree->GetEntries();
tree->SetEstimate(size);
// draw data as TGraph
tree->Draw("TC:L");
TGraph *g = new TGraph(size,tree->GetV1(),tree->GetV2());
g->GetYaxis()->SetTitle("L");
g->GetYaxis()->CenterTitle(1);
g->GetXaxis()->SetTitle("T");
g->GetXaxis()->CenterTitle(1);
g->SetLineColor(1);
g->Draw("al");
// remove the current axis
g->GetXaxis()->SetLabelOffset(999);
g->GetXaxis()->SetTickLength(0);
// redraw the new axis
gPad->Update();
TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
gPad->GetUymin(),
gPad->GetUxmin(),
gPad->GetUymin(),
g->GetXaxis()->GetXmin(),
g->GetXaxis()->GetXmax(),
510,"-");
newaxis->SetLabelOffset(-0.03);
newaxis->Draw();
c1->Write();
c1->SaveAs("data07.eps");
}
Thanks a lot!
Boginja