How to define the log format and scale value of a color palette?

Dear experts:
I want to define the log format of the palette like this

But I did draw it like this

So please tell me how to set the scale of the color palette and evenly divide it in logarithmic form。

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Welcome to the ROOT forum

You should define you own palette as explained here:

Using TColor::CreateGradientColorTable()

Thank you .And I want to know how to control the scale of the z-axis in logarithmic form , like in the first picture,from 1.0E-0.8 to 1.0E+01.Can ROOT achieve such a function?

Look at the way TColor::CreateGradientColorTable() is working . You can define the color change at the exact position you need. Simply put them where needed for your case.

const Int_t Number = 6;
Double_t Red[Number] = { 1.00, 0.00, 0.00,0.00, 0.50, 1.00};
Double_t Green[Number] = { 0.00, 1.00, 0.00,0.00, 0.00, 1.00};
Double_t Blue[Number] = { 1.00, 0.00, 1.00,1.00, 1.00, 1.00};
Double_t Length[Number] = { 0,1.0E-08, 1.0E-06, 1.0E-04, 1.0E-02, 1.0};
Int_t nb=100;
Is my code correct?Maybe it’s my data problem.But I still want to know if there is a way to manually adjust the range of values displayed on the z-axis?They always set it automatically.Like the second picture, I want to display more scales, such as 1.0E-4,1.0 E-5,etc. Is there any way to achieve this?
Thank you very much!

the dynamic of the two plots are different. On the 1st plot you have 10 decades and on the 2nd one 3. Change the minimum and the maximum of your histogram to match the 1st plot ones and you will get more decades.


I encountered a problem when plotting a 2D histogram using h1->Fill(z, x, a) , where z and x are coordinates, and a is the value of the fluence. The results show that the data range is between 0 and 3, which is not the case. I can see from my txt file that the flux values are very large. So, I would like to know if the 2D plot generated by ROOT truly reflects the actual data size, or if there has been some data processing operation that I am unaware of.
zy3.pdf (328.6 KB)
The reason there is a large amount of data is because I am plotting the flux on the zx plane, and along the y-direction, I have divided it into 100 grids. Therefore, each zx point has 100 flux values accumulated together. From the graph, it is evident that the flux values are very large, and it is impossible for them to be between 0 and 2.

Can you provide a reproducer ?

drawzx.cpp (3.2 KB) (2.7 MB)

I get this, what is wrong ?

Are the numbers on the right side of the color palette is the ‘a’ values I filled in the histogram? They don’t seem to match up.

Yes they are. Let me see your code

I simplified your code and I get this now:

void drawzx() {
   ifstream in;"cellfluxeminus.txt",ios_base::in); //read data

   string line;
   double x;
   double y;
   double z;
   double a,b,c;
   string str;

   int nlines = 0;
   double mass_array[200];
   double neutron_array[200];

   for (int i = 0; i < 200; i++) {
    mass_array[i] = neutron_array[i]= 0;

   auto c1 = new TCanvas();

   auto h1 = new TH2F("HIST","Electron fluence", 80, -20, 100,80, -1, 1);

   while (getline(in, line)) {
      std::istringstream iss(line);
      char comma;
      if (!(iss  >> x >> comma >> y >> comma >> z >> comma >> a >> comma >> b >> comma >> c)) {
        std::cerr << "Failed to parse line: " << line << std::endl;
      h1->Fill(z*120/100-20, x*2/100-1, a);


I got it. Thank you !!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.