# How to change colz color bar range to represent all z values?

**URL:** <https://root-forum.cern.ch/t/how-to-change-colz-color-bar-range-to-represent-all-z-values/43647>\
**Category:** Newbie\
**Created:** [February 21, 2021, 5:14pm UTC](https://root-forum.cern.ch/t/how-to-change-colz-color-bar-range-to-represent-all-z-values/43647 "2021-02-21T17:14:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cepheides](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bcef8e/32.png) [@Cepheides](https://root-forum.cern.ch/u/Cepheides)\
**Post date:** [February 21, 2021, 5:14pm UTC](https://root-forum.cern.ch/t/how-to-change-colz-color-bar-range-to-represent-all-z-values/43647/1 "2021-02-21T17:14:21Z")

</div>

I am creating a 2D color plot with the following code:

```auto
// Creates a plot of the logarithm of the luminosity due to helium burning in a star as a function of time and space
// V2: Added tick marks and labels to denote different evolutionary stages
// V3: Changed number of contourso equal the maximum number of colors for smoother color transitions
// added variable for center

# include <iostream>
# include <fstream>
# include <math.h>
# include <iomanip>
# include <cmath>
# include <stdlib.h>
# include <cstdlib>
//# include <fstream.h>
# include <string.h>
# include <string>
//# include <dos.h> //For Sleep() 

# include "TROOT.h"
# include "TFile.h"
# include "TTree.h"
# include "TBrowser.h"
# include "TH1.h"
# include "TH2.h"
# include "TH3.h"
# include "TGraph2D.h"
# include "TRandom.h"
# include "TLine.h"

int main(){

	const char *inputFileName = "log_He_500.dat";
	
	// ages
   double TAMS_age = 11.17874;
   double RGB_TIP_age = 12.75403;
   double AGB_age = 12.88079;
   
   // controls
   int palette_number = 62;
   int contour_number = 255;
   bool HB_zoom = false;

   // create the coordinate arrays
   vector<double> ages;
   vector<double> zones;
   vector<double> log_LHes;
   vector<double> dx;
   vector<double> dy;
   vector<double> dz;

   ifstream inFile(inputFileName);

   if (inFile.is_open())cout<<"Input File was opened successfully"<<endl;

   //Main loop filling arrays from file//
   double lineage, linezone, lineHe;
   while (inFile>>lineage>>linezone>>lineHe) {
      ages.emplace_back(lineage);
      zones.emplace_back(linezone);
      log_LHes.emplace_back(lineHe);
      dx.emplace_back(0);
      dy.emplace_back(0);
      dz.emplace_back(0);
   }
   cout << "Read " << ages.size() << " lines\n";
   auto center = max_element(begin(zones), end(zones));
   cout << "Maximum zone (center) is " << *center << endl;
   int center_zone = *center;

   gStyle->SetPalette(palette_number);
  /* const Int_t Number = 3;
   Double_t Red[Number] = { 1.00, 0.00, 0.00};
   Double_t Green[Number] = { 0.00, 1.00, 0.00};
   Double_t Blue[Number] = { 1.00, 0.00, 1.00};
   Double_t Length[Number] = { 0.00, 0.50, 1.00 };
   Int_t nb=1000;
   TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
   */
   gStyle->SetNumberContours(contour_number);

   auto c1 = new TCanvas("c1","log_LHe vs zone and age",200,10,1200,1000);

   TGraph2DErrors *gr = new TGraph2DErrors(ages.size(),&ages[0],&zones[0],&log_LHes[0],&dx[0],&dy[0],&dz[0]);
   gr->SetTitle("log_LHe;star age (Gyr);zone number");        
   gPad->Modified();
   gr->Draw("colz");
   gPad->Update();
   
   if (HB_zoom) {
		gr->GetXaxis()->SetRangeUser(RGB_TIP_age-0.2,AGB_age+0.2);
   } else {
		gr->GetXaxis()->SetRangeUser(TAMS_age-0.7,AGB_age+1.0);
   }
      
   //////////////////////////////////////////// TICK MARKS ////////////////////////////////////////////////////////
   	// TAMS 
   auto TAMS = new TLine(TAMS_age,center_zone,TAMS_age,center_zone+6);
   TAMS->SetLineColor(kBlack);
   TAMS->SetLineWidth(2);
   TAMS->Draw();
  
	// RGB TIP / Start of HB
   auto RGB_TIP = new TLine(RGB_TIP_age,center_zone,RGB_TIP_age,center_zone+6);
   RGB_TIP->SetLineColor(kBlack);
   RGB_TIP->SetLineWidth(2);
   RGB_TIP->Draw();
	
	// marker
   auto line = new TLine(12.75531,0,12.75531,center_zone);
   line->SetLineColor(kRed);
   line->SetLineWidth(2);
   line->Draw();
   
   // AGB / End of HB
   auto AGB = new TLine(AGB_age,center_zone,AGB_age,center_zone+6);
   AGB->SetLineColor(kBlack);
   AGB->SetLineWidth(2);
   AGB->Draw();
   
   //////////////////////////////////////////////////////// LABELS ///////////////////////////////////////////////////////
   auto latex_MS = new TLatex(TAMS_age-0.4,center_zone+8,"MS");
   latex_MS->SetTextSize(0.015);
   latex_MS->Draw();
   
   if (!HB_zoom){
	   auto latex_RGB = new TLatex(12.00,center_zone+8,"RGB");
	   latex_RGB->SetTextSize(0.015);
	   latex_RGB->Draw();
   }
   
   auto latex_HB = new TLatex((RGB_TIP_age+AGB_age)/2. ,center_zone+8,"HB");
   latex_HB->SetTextSize(0.015);
   latex_HB->Draw();
   
   auto latex_AGB = new TLatex(13.00,center_zone+8,"AGB");
   latex_AGB->SetTextSize(0.015);
   latex_AGB->Draw();
	
	return 0;
}

```

Here is the input file if you would like to replicate this: [log\_He\_500.dat](https://www.dropbox.com/s/n0i6pp05ysu28y3/log_He_500.dat?dl=0)

 ![loglhe](https://root-forum.cern.ch/uploads/default/original/3X/9/6/9621a5039b5ef9f2bf537c17ce052011bc9133dd.png)

The issue is, under the region labeled “HB” between the ticks, I was expecting to see the highest z values in the upper zones (z ~ 30, you can also verify this yourself in the data file I attached). However, instead the colors indicate with the black color that there are no z values there.

Is this because the range of the color bar is limited? If so, I was wondering if there was a way to change the color bar range so that it represents the full range of z values and doesn’t cut off arbitrarily and affect the accuracy of the colors?

Thanks,

_ROOT Version:_ 6.22/02  
_Platform:_ Ubuntu 18.04

* * *

---

<div class="post-metadata">

**Author:** ![AdvaitDhingra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/advaitdhingra/32/32443_2.png) [@AdvaitDhingra](https://root-forum.cern.ch/u/AdvaitDhingra)\
**Post date:** [February 21, 2021, 8:15pm UTC](https://root-forum.cern.ch/t/how-to-change-colz-color-bar-range-to-represent-all-z-values/43647/2 "2021-02-21T20:15:45Z")

</div>

I think [this](https://root.cern/blog/rainbow-color-map/) article may be helpful.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 22, 2021, 7:39am UTC](https://root-forum.cern.ch/t/how-to-change-colz-color-bar-range-to-represent-all-z-values/43647/3 "2021-02-22T07:39:20Z")

</div>

You are using a TGraph2D. When you use the `COLZ` drawing option the corresponding histogram filled from the graph is drawn.  
Here are two plots. The first one is generated with the drawing option `P0` which draws all the points in the TGraph2D and the 2nd was produced with the `COLZ` option but with an increased number of bins for the underlaying histogram. This is done using:

```auto
   gr->SetNpx(100);
   gr->SetNpy(100);

```

As you can see the two plots match.  
There is this flat area below the HB label.

 ![Screenshot 2021-02-22 at 08.30.28](https://root-forum.cern.ch/uploads/default/original/3X/8/5/85c1128093c0f58f3611b28443cb9de6bf26d687.jpeg)  
 ![Screenshot 2021-02-22 at 08.31.40](https://root-forum.cern.ch/uploads/default/original/3X/b/2/b213f2cded26e686f13d9c112c48602ea2190e72.jpeg)
