Rotation of 1D histogram


I have a wish to make a plot with 2 1D histogram and 1 2D histogram. The layout will be similar to the one in the attachment, which I believe is made pasting 3 histograms in PhotoShop. That’s is kind of cheating to me. :wink:

Is there a way in ROOT to rotate the left histogram as shown in the attachment? The “HBAR” option to TH1::Draw results in the histogram being drawn on the “opposite” y axis, so I can not use it. I see that THistPainter::Paint calls TPad::SetVertical, whatever that means. Will I have to modify the code of THistPainter to a histogram to be drawn the way I want?

I am currently using ROOT 3.10/02 on a Debian GNU/Linux testing distribution.

Best wishes from
Jens Ivar

Hi Jens,

Have a look at the 3 examples in the attachement

projxy2.C (6.4 KB)
projxy.C (3.26 KB)
ProjectBoth.C (3.18 KB)

Thanks René.
Those tricks are nevertheless quite limiting.
Why couldn’t the basic TH1D drawing options apply to horizontal histograms ?
At least, could you please provide the possibility to rotate a TPad by +/- 90 deg ?

[quote=“jens”]…I have a wish to make a plot with 2 1D histogram and 1 2D histogram. … [/quote]Please, find a working QtRoot project to produce the screenshot attached. Is it what you want ?
The main job is provided by two methods:

[code]void HelloHistRotation::updateHistograms()
static int ii = 0;

Float_t px, py, pz;
Int_t j = 0;

for (Int_t i = 0; i < 50; i++,ii++) {
pz = pxpx + pypy;
if (ii == 48) {
// Attach each object to the dedicated pad at once
fPads[0]->cd(); fHpx ->Draw();
fPads[1]->cd(); fHpxpy->Draw(“COLZ”);
fPads[2]->cd(); fHprof->Draw();
if (ii > 6000) {
ii = 100;
for (j=0;j<3;j++) {

void HelloHistRotation::paintEvent( QPaintEvent *) { QPainter paint( this ); QSize wsize = size(); for (int i=0;i<3;i++) { Double_t rotn = gRandom->Rndm()*10; // define the rotation angle int ax = int(gRandom->Rndm()*2.3); // define the rotation axis Qt::Axis axis = Qt::ZAxis; switch (ax) { case 0: axis = Qt::XAxis; break; case 1: axis = Qt::YAxis; break; }; QSize psize = pix.size(); // define the TPad position on the screen int x = int(gRandom->Rndm() * float( wsize.width() - psize.width())); int y = int(gRandom->Rndm() * float( wsize.height() - psize.height())); paint.drawPixmap(x,y ,TQtUtil::padPixmap(fPads[i])->transformed(QTransform().rotate(rotn*36.,axis))); } }Of course, your case is slightly simpler then that. I hope you can simplify the code further yourself.
HelloHistRotation.tar.gz (3.07 KB)

You do not need Qt to get rotated pictures. Simply use the TASimage class as shown below

[code]void imag()
TCanvas *c1 = new TCanvas(“c1”,“c1”,800,600);;
TH1F *h = new TH1F(“gaus”, “gaus”, 100, -5, 5);
h->FillRandom(“gaus”, 10000);

TCanvas *c2 = new TCanvas(“c2”,“c1 rotated”,600,800);;
TImage *img = TImage::Create();


[quote=“brun”]You do not need Qt to get rotated pictures. [/quote]Yes, correct; but … one needs that “simple” idea :wink: does it :unamused: ? Of course, it does not matter which third party software package one uses to implement it.

Thanks Valeri and René.

The TImage trick is still very limiting.
Getting back a static image requires playing with dimensions to have a nice display, which is a nightmare.

As for the QT thing, I don’t know where to “find a working QtRoot project” :blush:
If it is still possible to “play” with the rotated pad (zoom, label, etc.),
could you please indicate me a basic working QtRoot project Valeri?


[quote=“Zesp”]As for the QT thing, I don’t know where to “find a working QtRoot project” :blush: [/quote] The project (see: ) and then build the project as follows: wget '' -O HelloHistRotation.tar.gz tar -xzvf HelloHistRotation.tar.gz qmake make The example above is included into the QtRoot “qtExamples” suite. The qtExamples is a part of the QtRoot source tree.[quote=“Zesp”]If it is still possible to “play” with the rotated pad (zoom, label, etc.),[/quote]Well, “label” and “zoom” are quite different things.
Anyway, to “play” one needs to be able perform 2 transformations. One to rotate the image and another one (inverse one) to map the mouse pointer coordinates back to that rotated image. The later is needed to allow to point and pick the correct ROOT object.
This second part (mouse pointer mapping) has no ready-to-eat implementation. However, you can do it yourself for your concrete task. (The things are to be trivial but require you to learn Qt :unamused: ). I really reluctant to provide any generic solution that is not backed by any ROOT abstract interface.
From your original description, I understand you can play with the “straight” TCanvas with no problem. This way one may survive with no “inverse mouse pointer coodinates transformation”[quote=“Zesp”]could you please indicate me a basic working QtRoot project Valeri?[/quote] Upon installation of QtRoot you should find two dozens different working basic qt projects. The one that I attached above can be found under “qtRoot/qtExamples/HelloDancingHist” directory.
Try it to see whether it can meet your needs.

Thx Valeri.
I’ll have a look and let u know.
Cheers, Z

Sorry to dig up this topic but I would like to do exactly the same picture as the one shown in the first post.
Is there any new way to do so in the latest version of ROOT (ROOT 5.34/32 or ROOT 6.04/02)?
Basically, what Zesp proposed (to be able to rotate by +/- 90° a TH1) would be really nice.

Hi pamputt,
Actually I proposed something in the past but it didn’t go very far…

I went a bit further in the meantime (see the pdf below)
but did not find time to finalize it properly.
I’ll try to resubmit something by the end of summer
unless Root developers work on something. Do you, guys ?
2D_zmin0_yminneg_xminneg_logx0_logy0_logz0.pdf (18.4 KB)

Thank you Zesp for your effort.
In the meantime, I asked for reopening JIRA-2476.

Thx :wink:

May be add it in the now re-openned JIRA ticket ?

nothing new here? still only hbar is usable!

could I rotate TPad directory?

See axel comment at the end of the Jira ticket.