Making the both axes square on the pad

Hi,

Is there a way to force TH2 to draw with both axes the same length? Or more importantly same scale? I’m trying to draw a TH2F where the axes are both in the same units and I’d like it to print that way. Trouble is, I also adjust the pad margins and this seems to affect the overall length of one axis relative to the other.

Thanks,
Bob

Yes, of course, if you change the margins the plot may not be square any more. Can you send a small example showing what you thingk is wrong ?

Hi,

I’m attaching a script that just draws the pad with the same code that I use. I’ve removed the part that fills the histogram. The reason that I need to adjust the pad margins is because otherwise I lose the labels on the color axis. Is there a way to force the histogram to draw each axis to the same scale regardless of what is done to the pad?

Thanks,
Robert
test.C (1.8 KB)

You can use gPad->SetFixedAspectRatio();

Hi Again,

So gPad is the global pointer to the current active pad. I have mulitple canvases open, so I figured that since TCanvas inherits from TPad I could use the TPad::SetFixedAspectRatio() on the canvas itself. For example:
{
TCanvas *c = new TCanvas(“c”,"",500,500);
c->SetFixedAspectRatio();
}
However, using gStyle->SetPadXXXMargin( ) still causes the aspect ratio to change between the x and y axes.

I’m also using root version 4.00/08 and do not have permission to upgrade (at least for the time being).

Thanks,
Robert

yes sorry you should do it on canvas

Hi,

I do it on the canvas, like I said above, and it still doesn’t work. I notice no difference between when I use it and when I don’t. Do I have to somehow grab the pad that’s in the canvas after the TH2F is drawn and set it then? If so, what’s the easiest way to do it?

Thanks,
Robert

With the following values in your macro you get a square:

  Float_t leftmargin  = 0.1;
  Float_t rightmargin = 0.12;
  Float_t topmargin   = 0.045;

Hi,

I dont want to have edit the margins to both get the color axis and to get the x-y axes square.

When I dump the TCanvas object I find that these are the values I would like to change in my script. The methods TCanvas::GetX1(), etc., return me these values.

fX1 -1.40755 X of lower X coordinate
fY1 -1.59144 Y of lower Y coordinate
fX2 1.36981 X of upper X coordinate
fY2 1.1323 Y of upper Y coordinate

To change these values I’ve found that TPad::Range(x1,y1,x2,y2) works; however, I can’t figureout how to make the histogram adjust to these new settings. TPad::RangeChanged(), Update(), and Draw() seem to do nothing.

Thanks,
Robert

see the short example below

[code]{
//method1. compute ymax to get a commensurate range
// 1 pixel must correspond to the same range in x and y
TCanvas c1(“c1”,“c1”,10,10,800,600);
Float_t xmin = 0;
Float_t xmax = 20;
Float_t ymin = -2;
Int_t npx = gPad->GetWw();
Int_t npy = gPad->GetWh();
Float_t ymax = ymin + (xmax-xmin)*npy/npx;
TH2F h(“h”,"",20,xmin,xmax,20,ymin,ymax);
h.Draw();
TArc a1(6,4,6);
a1.Draw();

//method2. set a square virtual canvas size in a non-square canvas
TCanvas c2(“c2”,“c2”,200,50,800,600);
c2.SetCanvasSize(700,700);
c2.DrawFrame(0,0,20,20);
TArc a2(10,10,10);
a2.Draw();
}
[/code]

Rene

Hi,

Method 2 works if I dont adjust the pad margins. See attached for an extreme example. Trouble is, I would like to adjust the pad margins, and have square axes without having to guess at their proportions everytime.

Thanks,
Robert
test.C (2.11 KB)