Re: Cannot set log scale

From: Yaxian Mao <maoyx_at_iopp.ccnu.edu.cn>
Date: Tue, 8 Jul 2008 23:33:09 +0800


Hi,
  I guess your y-axis range from 0 or negative value. In this case you could not do log scale with y<=0...
  Cheers...Yaxian

Erkcan Ozcan wrote:
> Hi,
>
> I have a macro to read some 1D histograms from a file and draw them.
> If I do gPad->SetLogy() before drawing, the histograms are nicely
> plotted in the log scale. However if I draw the histograms first and
> then try to switch to log scale (either by issuing gPad->SetLogy() or
> simply by right clicking the TPad and choosing log scale in the menu),
> I get the error:
>
> Error in <THistPainter::PaintInit>: log scale requested with zero or
> negative argument (0.000000)
>
> To overcome this problem I implemented a function (attached below) to
> loop through all the 1D histos on the gPad and SetMinimum() for all of
> them before calling gPad->SetLogy().
>
> While this solves my problem, I still find it unintuitive to go
> through all this. While protection against negative arguments makes
> sense, bins with zero content are encountered quite often, so I am not
> sure if the current behavior is really desired for them.
>
> My question: 1-Is there a gStyle kind of switch which turns off this
> error? (I am using ROOT 5.18/00.) 2-If not, could it be implemented in
> a future release of ROOT?
>
> Thanks,
>
> Erkcan
>
>
> void PadToLogScale() {
>
> if ( gROOT->GetListOfCanvases()->GetEntries() == 0 ) return;
> if ( gPad->GetLogy() ) return;
>
> TPad *oldpad = gPad;
>
> // Now loop through histos and find the extrema
> TList *glist = oldpad->GetListOfPrimitives();
> for (int i=0; i<glist->GetEntries(); ++i) {
> TObject *obj = glist->At(i);
> if ( obj->InheritsFrom("TH1") ) {
>
> // If there is a 2D histogram, don't do anything.
> if ( obj->InheritsFrom("TH2") ) return;
>
> TH1 *histo = (TH1*)obj;
> histo->SetMinimum();
>
> }
> }
>
> gPad->SetLogy();
> gPad->Modified();
>
> }
>
>
> --
>
> In case they are not written explicitly, please be aware that my
> greetings and farewell are inherently implied in this email.
>
> V. Erkcan Ozcan
> Research Fellow
> University College London
> Dept. of Physics & Astronomy
>
>
>


Received on Tue Jul 08 2008 - 17:48:09 CEST

This archive was generated by hypermail 2.2.0 : Tue Jul 08 2008 - 23:50:02 CEST