CreateGradientColorTable with PyROOT

Hello,

I’m trying to create a custom colour scheme for plots I’m making with PyROOT. I’m trying to use the following for the arrays of colours (using the same mechanism as used for variable bin widths):

[code]#!/usr/bin/env python

from ROOT import gStyle
from ROOT import gROOT
from ROOT import TStyle
from ROOT import TColor

from array import array

my colour scheme

NRGBs = 6
NCont = 99
stops = [ 0.00, 0.02, 0.34, 0.51, 0.64, 1.00 ]
red = [ 1.00, 0.00, 0.00, 0.87, 1.00, 0.51 ]
green = [ 1.00, 0.00, 0.81, 1.00, 0.20, 0.00 ]
blue = [ 1.00, 0.51, 1.00, 0.12, 0.00, 0.00 ]
stopsArray = array(‘f’, stops)
redArray = array(‘f’, red)
greenArray = array(‘f’, green)
blueArray = array(‘f’, blue)
TColor.CreateGradientColorTable(NRGBs, stopsArray, redArray, greenArray, blueArray, NCont)
gStyle.SetNumberContours(NCont)[/code]

I get the following output:

Traceback (most recent call last): File "./ColorTest.py", line 21, in <module> TColor.CreateGradientColorTable(NRGBs, stopsArray, redArray, greenArray, blueArray, NCont) TypeError: static Int_t TColor::CreateGradientColorTable(UInt_t Number, Double_t* Stops, Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors) => could not convert argument 2

Am I doing something wrong?

My ROOT version (from root --version) is:
ROOT 5.26/00 (trunk@31882, Dec 14 2009, 20:18:36 on linuxx8664gcc)

Many thanks in advance,

Tom

Tom,

the interface needs a Double_t*'s which is indicated on the array by using ‘d’ not ‘f’ (which is for float; and yes, python’s float is a double, but the type codes come from C).

Cheers,
Wim

Dear Wim,

Great, many thanks for that - I missed the ‘d’ code in the Python array documentation (and ‘f’ appears to work for the histogram binning - something I can/should change as well!).

With best wishes,

Tom