Printing TCanvas using custom palette

Hi,
I’m plotting a scatter plot using a custom palette, defined as the same as written on page 135 of ROOT5.21 manual.

//Example of creating new colors and defining a new palette
void palette(int nCol) {
  if (nCol <=0 || nCol >20)
    nCol= 20;
  const int colNum= nCol;

  int startCol=210;
  double colRatio=1.0;
  int palette[ colNum];
  for(int i=0; i<colNum; i++) {
    // get the color and if it does not exists create it
    if( i < (colNum+1)/2) {
      if(! gROOT->GetColor(startCol+i))
	TColor *color= new TColor(startCol+i,(i/( colNum/2*colRatio)), (i/( colNum/2*colRatio)), 1,"");
      else {
	TColor *color= gROOT->GetColor(startCol+i);
	color->SetRGB( (i/( colNum/2*colRatio)), (i/( colNum/2*colRatio)), 1 );
      }
    }
    else if (i == (colNum+1)/2) {
      if(! gROOT->GetColor(startCol+i))
	TColor *color= new TColor(startCol+i,1,1,1,"");
      else {
	TColor *color= gROOT->GetColor(startCol+i);
	color->SetRGB( 1,1,1 );
      }
    }
    else {
      if(! gROOT->GetColor(startCol+i))
	TColor *color= new TColor(startCol+i,1,colRatio-(i/( colNum/2*colRatio)),colRatio-(i/( colNum/2*colRatio)),"");
      else {
	TColor *color= gROOT->GetColor(startCol+i);
	color->SetRGB( 1, colRatio-(i/( colNum/2*colRatio)),colRatio-(i/( colNum/2*colRatio)) );
      }
    }
    palette[i] = startCol+i;
  }
  gStyle->SetPalette(colNum,palette);
}

This function is intended to define a palette of colors from plain blue shading to white, then to deep red.

The problem is that, while the TCanvas is perfect,

the printed eps file show just the blue colors spectrum and no difference in red colors.

Any hints to solve this little problem?

ps: if I print using a standard palette, using

gStyle->SetPalette(1);

everything works fine, but I cannot obviously obtain the effect I want.

That’s a gv screen dump. Have you tried to print it ? gv as a bug with anti aliasing press “a” in the gv window. Does that help ?

I tried to remove antialias in gv.
The problem is that the picture has the bad shape into a latex document too (pdf - didn’t check dvi).

I see that red in fully red in PS using your macro. I investigate.

When you define the red colors the green and blue components are negative.
I put a printf in your macro:

   color->SetRGB( 1, colRatio-(i/( colNum/2*colRatio)),colRatio-(i/( colNum/2*colRatio)) );
   printf("%g\n",colRatio-(i/( colNum/2*colRatio)));

I get:

root [0] .x palette.C(20)
-0.1
-0.2
-0.3
-0.4
-0.5
-0.6
-0.7
-0.8

Thank you!
I forgot to reinitialize the index when defining red spectrum:

if(! gROOT->GetColor(startCol+i))
  TColor *color= new TColor(startCol+i,1,colRatio-((i-(colNum+1)/2)/( colNum/2*colRatio)),colRatio-((i-(colNum+1)/2)/( colNum/2*colRatio)),"");
else {
	TColor *color= gROOT->GetColor(startCol+i);
	color->SetRGB( 1, colRatio-((i-(colNum+1)/2)/( colNum/2*colRatio)),colRatio-((i-(colNum+1)/2)/( colNum/2*colRatio)) );
}

Now it works.