I want to rotate my axis labels to an arbitrary angle. I first fill the axis label with test via
hist->GetXaxis()->SetBinLabel(1,"-300<#DeltaE<200")
hist->GetXaxis()->SetBinLabel(2,"m_{ES}>5.27 GeV")
etc.
and the labels are too long to fit horizontally. I did a search in RootTalk but could not find any relevant discussions. Ironically, I googled “rotating axis labels” and this old (2000) posting popped up. Is it possible to do with ROOT v3.10?
Thanks.
Re: [ROOT] rotating axis labels
From: Damir Buskulic ([buskulic@lapp.in2p3.fr](mailto:buskulic@lapp.in2p3.fr))
Date: Wed Jul 26 2000 - 18:01:30 MEST
* Next message: Ralph Mueller-Pfefferkorn: "Re: [ROOT] rotating axis labels"
* Previous message: Valeri Fine (Faine): "Re: [ROOT] Windows 2000"
* In reply to: Ralph Mueller-Pfefferkorn: "[ROOT] rotating axis labels"
* Next in thread: Ralph Mueller-Pfefferkorn: "Re: [ROOT] rotating axis labels"
* Reply: Ralph Mueller-Pfefferkorn: "Re: [ROOT] rotating axis labels"
* Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Ralph,
For the moment, I think it is impossible to do. Can't you choose a time
format that fits horizontally ? What is the format ?
Damir
Ralph Mueller-Pfefferkorn wrote:
>
> Hi Rene,
>
> how can I rotate the labels of an axis (TH*/TGraph) ?
>
> I want to plot something versus date. As the date is a long label I would
> like to rotate it that the labels are vertical to the axis. But I could
> not find out how to do that.
> Could you help me, please ?
>
> Greetings, Ralph
>
> --
> Ralph Mueller-Pfefferkorn email: [mueller@pktw06.phy.tu-dresden.de](mailto:mueller@pktw06.phy.tu-dresden.de)
> Institut f. Kern- und Teilchenphysik, TU Dresden, 01062 Dresden, Germany
> Office ASB E25 Phone: +49-351-463-2957 Fax: +49-351-463-3114
> __o o__ o__ o__ o__ o__ o__
> \<,_ _.>/ _ _.>/ _ _.>/ _ _.>/ _ _.>/ _ _.>/ _
> (_)/ (_)_________(_) \(_) (_) \(_) (_) \(_) (_) \(_) (_) \(_) (_) \(_)__
--
=====================================================================
| Damir Buskulic | Universite de Savoie/LAPP |
| | Chemin de Bellevue, B.P. 110 |
| Tel : +33 (0)450091600 | F-74941 Annecy-le-Vieux Cedex |
| e-mail: [buskulic@lapp.in2p3.fr](mailto:buskulic@lapp.in2p3.fr) | FRANCE |
=====================================================================
mailto:buskulic@lapp.in2p3.fr
Is there an update to this? I found what I think were these, but they didn’t really explain it. I also found the method SetTextAngle, but I’m not sure what to call it from.
So, is it possible to get rotating labels for an axis?
Consider this python example of a time dependent bin size. The axis labels look ugly, the dates are too close together. I would like them to go at an angle, like the ones in the examples you provided, but I want the axis to do this automatically, since the plot will be updates as time progresses. I want to use the axis’ treatment of time, so I would like to use the axis rather than a separate drawable object.
#!/usr/bin/env python
import ROOT
ROOT.gROOT.LoadMacro("scripts/AtlasStyle.C")
ROOT.SetAtlasStyle()
ROOT.gStyle.SetOptTitle(0)
def main():
from array import array
ROOT.gStyle.SetTimeOffset(0);
x = [1461168044L, 1461353937L, 1461583342L, 1461583828L, 1461590925L, 1461592425L, 1461595103L, 1461681830L, 1462790854L, 1463833176L]
Hist = ROOT.TH1D("hist", "hist",len(x)-1, array("d",x))
Hist.Draw("a")
Hist.GetXaxis().SetTimeDisplay(1);
Hist.GetXaxis().SetTimeFormat("%d-%m-%Y");
Hist.SetFillColor(5)
Hist.SetMarkerStyle(1)
y = [50,60,100,75,80,65,90,70,80,67]
for i in range(0,10):
Hist.SetBinContent(i,y[i])
Hist.Draw()
raw_input()
if __name__ == "__main__":
main()
That doesn’t sound right. I changed my example by increasing the label sizes (Hist.GetXaxis().SetLabelSize(0.07) but no automated rotation took place, they just uglily overlap. I made an example here: jrosten.web.cern.ch/jrosten/exampleBadLabel.pdf