I am currently creating a TH2F Histogram using the COLZ feature to draw it.
The z-axis is logarithmic with negative powers (10^-7, 10^-8 etc…) as such these values do not all appear on the canvas and I do not know how to shift the z-axis colour palette to the left a bit to resolve this problem (see attached file for an example of what I am trying to describe).
gPad->Update();
TPaletteAxis *palette = (TPaletteAxis*)my2dhisto->GetListOfFunctions()->FindObject("palette");
// the following lines move the palette. Choose the values you need for the position.
palette->SetX1NDC(0.9);
palette->SetX2NDC(0.95);
palette->SetY1NDC(0.2);
palette->SetY2NDC(0.8);
gPad->Modified();
gPad->Update();
I have a similar issue, and I tried the code you provided. However, I now get a segmentation fault. (Of note, I am using ROOT as libraries, rather than coding in the ROOT interpreter.)
// the following lines move the palette. Choose the values you need for the position.
palette->SetX1NDC(0.9);
palette->SetX2NDC(0.92);
palette->SetY1NDC(0.2);
palette->SetY2NDC(0.8);
gPad->Modified();
gPad->Update();[/code]
and I got this:
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
Thread 2 (process 79603):
#0 0x00007fff8607dc0a in kevent ()
#1 0x00007fff8607fadd in _dispatch_mgr_invoke ()
#2 0x00007fff8607f7b4 in _dispatch_queue_invoke ()
#3 0x00007fff8607f2de in _dispatch_worker_thread2 ()
#4 0x00007fff8607ec08 in _pthread_wqthread ()
#5 0x00007fff8607eaa5 in start_wqthread ()
Thread 1 (process 79603):
#0 0x00007fff860e2b28 in wait4 ()
#1 0x00007fff860f70e6 in system ()
#2 0x000000010166e87c in TUnixSystem::StackTrace ()
#3 0x000000010166ba21 in TUnixSystem::DispatchSignals ()
#4 <signal handler called>
#5 0x00000001000064d2 in main ()
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x00000001000064d2 in main ()
===========================================================
Just a stupid question … did you draw your “hist2” with an appropriate drawing option (e.g. “CONTZ”) that created the “palette” before you tried to run the code that gave you that “segmentation violation”?
To add… it’s not sufficient to draw the histogram in my case. I need to save the canvas first, say into a pdf, and only then the the histogram has the palette function.
Not sure if this is expected, but would like to mention it for others facing a similar problem.
After investigating further it was because I ran my macro in the -b mode. If I ran it without -b, indeed just gPad->Modified(); gPad->Update(); is sufficient, but with -b the canvas needs to be saved.
I tried to follow up on this discussion to move/resize the colour palette.
It ended up giving a warning: null passed to a callee that requires a non-null argument [-Wnonnull]
palette->SetY2NDC(0.7);
Could you kindly say what could be a problem here: