I have this annoying problem with the Pad axis limits command, GetUymax(). When I want to plot a vertical line on a plot, I normally do like this:
TLine *l = new TLine(0.5,c1->GetUymin(),0.5,c1->GetUymax());
This works very well for plots with a linear y scale. However, when I want to use a log scale, I observed the following:
- If I add the following line before the code above, I get a tiny line, for which Uymax is too small (Uymin looks ok):
- If I draw the plot from a macro in linear scale, and then request for SetLogy using the right-click menu of the Canvas, I get a longer line, but still missing something at the top.
Any idea why that happens and maybe how to go around it?
Thanks in advance,
I’ ll check an let you know.
Y max differs in log a linear scales (to show full decades. See plots). The best way is to use NDC coordinates:
Double_t x = 2.;
Double_t xndc = 0.8*((x-c.GetUxmin())/(c.GetUxmax()-c.GetUxmin()))+0.1;
This solution assumes that the histogram frame itself is located between 0.1 and 0.9 NDC in y, which is not always the case (in particular for ATLAS plot style). I can surely put this by hand for the moment, but I think it would be nice to have some way, maybe even a different method if needed, to return the Y max of a log plot, i.e. the maximum visible on the Canvas, which might be different than the linear y max to account for decades etc.
Sorry, I was lazy. I thought it was easy to make it general. Here is the general case:
TCanvas* c = new TCanvas("c", "c", 800, 800);
void DrawVerticalLine(Double_t x)
Double_t lm = gPad->GetLeftMargin();
Double_t rm = 1.-gPad->GetRightMargin();
Double_t tm = 1.-gPad->GetTopMargin();
Double_t bm = gPad->GetBottomMargin();
Double_t xndc = (rm-lm)*((x-gPad->GetUxmin())/(gPad->GetUxmax()-gPad->GetUxmin()))+lm;
I’m riviving this talk, because I have this doubt.
What happens if instead of a Tline I’m drawing a TGaxis? something like this:
TGaxis *Yaxis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax(),gPad->GetUymin(), gPad->GetUymax()/SCALEY ,510,"+L");
I can plot the axis using NDC coordinates, however I have to know the actual values of gPad->GetUymin()" and “gPad->GetUymax()” for the label, because the idea is to compare two histograms, but due to the Pad has Log scale, I cant get these actual values.
Right now I think that a possible solution is SetMaximum(h1->GetMaximum()+ topmargin) and a SetMinimum(h1->GetMinimum() - buttommargin) for the main histogram, but it does not look very practical.
Yes the labels is under your control. It can be anything.
Hi, I’m sorry to bump this topic but it’s just about a detail regarding the method described here. It works, but I also need to do c->SetBottomMargin(0.15), and after that gPad->GetBottomMargin() doesn’t get the correct position of the new bottom margin even when doing gPad->Modified(), gPad->Update(), c->Modified() and c->Update(). I would appreciate any help.
Can you post a code sample showing the problem ?
Trying to do that I realized that the issue was another, and it made things wrong only in combination with SetBottomMargin. Sorry for the noise, the original method works.