Inverse axis

hay
Can anybody tell me how to create a TGraph with Y-axis inverted i.e. the upper value is smaller than the lower value
thank you very much
best regards
florian

1 Like

nobody?
I tried GetYaxis()->SetRangeUser(-1.,1.) but this command does not allow me to invert the axis. Same with DrawFrame(80,-26,400,-12);

would be thankful for any help or hint
thanks
and best regards
florian

1 Like

ok if this is not possible does anybody know how to set the axis values manually?
thanks
florian

sorry for the late answer. here is an example:

reverseaxis ()
{
   TH2F *hpxpy  = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
   Float_t px, py;
   TRandom r;
   for (Int_t i = 0; i < 25000; i++) {
      r.Rannor(px,py);
      hpxpy->Fill(px,py);
   }
   TCanvas *c1 = new TCanvas("c1");
   hpxpy->Draw("colz");
   ReverseXAxis(hpxpy);
   ReverseYAxis(hpxpy);
}

ReverseXAxis (TH1 *h)
{
   // Remove the current axis
   h->GetXaxis()->SetLabelOffset(999);
   h->GetXaxis()->SetTickLength(0);

   // Redraw the new axis
   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
                                gPad->GetUymin(),
                                gPad->GetUxmin(),
                                gPad->GetUymin(),
                                h->GetXaxis()->GetXmin(),
                                h->GetXaxis()->GetXmax(),
                                510,"-");
   newaxis->SetLabelOffset(-0.03);
   newaxis->Draw();
}

ReverseYAxis (TH1 *h)
{
   // Remove the current axis
   h->GetYaxis()->SetLabelOffset(999);
   h->GetYaxis()->SetTickLength(0);

   // Redraw the new axis
   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmin(),
                                gPad->GetUymax(),
                                gPad->GetUxmin()-0.001,
                                gPad->GetUymin(),
                                h->GetYaxis()->GetXmin(),
                                h->GetYaxis()->GetXmax(),
                                510,"+");
   newaxis->SetLabelOffset(-0.03);
   newaxis->Draw();
}
1 Like

hi
thank you very much for your answer… Thats an interesting solution. However I thought it should be possible that all data points depend on the reversed axis. In your solution the data points still follow the previous axis. So if I have an increasing slope with the first axis and I reverse the axis, it would be nice to have a decreasing slope…
Nevertheless I can use your solution you gave I just have to adjust all values so they fit the second axis scale.
thanks again
and best regards
florian

Yes, that’s the request we generally have but that’s not implemented yet.

Please Olivier…
Thanks, Z

I am waiting for the implementation since, if I remember correctly, 2006 :slight_smile: Any chances for it any time soon? It’s a must-have for most astrophysical data…

Olivier being away for one week, I will attempt to answer ::slight_smile:
We understand that negative axis are important for the astro community, and indeed this
request was made many years ago. Olivier has a long list of things to do on his “todo” list.
We are trying to prioritize the items on this list in function of the perceived priorities
for our High Energy Physics domain where nobody is requesting this facility.
Implementing negative axis may look a trivial thing to implement a priori. This is may be true
for a pure plotting package, but we have to make this implementation consistent with many other things, picking, editing, etc.
Unfortunately this corner of the graphics system requires the knowledge of all problems and cannot be easily implemented as an “outside” contribution, although we do not refuse volunteers, and we already had many volunteers from the Astro community.

Rene

I understand. I guess everyone using root and needing inverse axis has now some standard code to do that :slight_smile:

Yes, but as there is no standard way in ROOT to have the Pad coordinates along X and Y axis going the reverse way, it can be only tricks. And such are already listed in how-to, faqs, etc…
In fact the request is really that ie: having reverse pad coordinates.

I have the same request, has this been accommodated since 2009? Anyway, as an exercise I tried the example above with Version 5.34/03 with the crash message below. What went wrong with my installation of this version?
Thanks for the help

Hi,

the problem with the macro from 2009 is due to CINT being more strict
now. (functions need void …) Att a macro which should work with CINT and ACliC.

Cheers
Otto
reverseaxis.C (1.81 KB)

1 Like

Hi, has this been implemented since 2009?

https://root.cern/doc/master/classTGraphPainter.html#GrP6

Hi @couet ,

Thanks for the help. Though is this only available for 1D graphs? I am trying to use RZ for a TH2F and it has no effect.

Thanks,
Jack

Yes for X and Y axis only.
For 3D plots its is more tricky… the lego plot (for instance) would have to be drawn upside down.

Hi @couet ,

Ah ok, the lego plot being drawn upside down is exactly what I want (I have some plots were the important points are the points with the lowest value and it would be much easier to see them if they were shown as peaks in the lego plot, rather than troughs. I guess this isn’t possible in ROOT.

Thanks for your help,
Jack

You can may be create a new histogram which is the difference between your histogram and cube histogram of the same Z range ?

Hi @couet ,

Thanks for the suggestion (I’m currently doing something similar, just plotting 1/value, all values are guaranteed positive in my case) which should work but it would also be nice for the axis values to show the correct values