def __init__(self):

        self.p_n = [
            0,
        ] * 100
        self.e_n = [
            0,
        ] * 100
        self.stored_parameters = [
            0,
        ] * 100

        self.num_bins = 0
        self.xmins = []
        self.xmaxes = []

        self.data = []
        self.errors = []
        self.data_fits = []

        self.model_scale_values = []
        self.final = False

        self.exclude_regions = ((0, 0), )

        self.col1 = 1
        self.col2 = TColor.GetColor(27, 158, 119)
        self.col3 = TColor.GetColor(217, 95, 2)
        self.col4 = TColor.GetColor(117, 112, 179)
Пример #2
0
    def __init__(self,
                 subprocesses,
                 tree,
                 label,
                 line_color=1,
                 fill_color=0,
                 marker_style=None,
                 metadata=None):
        """Initializes a new instance of the Process class.

        Args:
            subporocesses: An iterable of processes
            label: The ROOT TLatex label string to use when rendering the
                process
            line_color: The ROOT TColor number or hex string (#rrggbb) to use
                as the line color when rendering the process
            fill_color: The ROOT TColor number or hex string (#rrggbb) to use
                as the fill color when rendering the process
            marker_style: The ROOT TMarker number to use as the marker style
                when rendering the process
            metadata: A (pickleable) object containing optional metadata
        """
        # Store parameters
        self._subprocesses = subprocesses
        self._label = label
        self._line_color = line_color
        self._fill_color = fill_color
        self._marker_style = marker_style
        self._metadata = metadata

        # Translate hex colors if necessary
        if isinstance(self._line_color, string_types):
            self._line_color = TColor.GetColor(self._line_color)
        if isinstance(self._fill_color, string_types):
            self._fill_color = TColor.GetColor(self._fill_color)
Пример #3
0
 def __new__(cls, r, g, b, name=""):
     self = int.__new__(cls, TColor.GetFreeColorIndex())
     self.object = TColor(self,
                          float(r) / float(255),
                          float(g) / float(255),
                          float(b) / float(255), name, 1.0)
     self.name = name
     return self
Пример #4
0
def createCanvas(event, goodJets, goodBJets, Leptons, etmiss, imageDir) :

    pt_bins = [0.,10.,20.,30.,50.,100.,250.,500.,1000.,1500.,2000.]
    histo_bin =  ROOT.TH1D("hito_bins", "p_{T} [GeV]", len(pt_bins)-1, array('d', pt_bins))

    # Create the empty figure
    ecolors = {"leptons" : TColor(10007, 0., 1.0, 0.), "bjet" : TColor(10004,1., 0., 0.), "jet": TColor(10003,1,0.5,0.5), "etmiss" : TColor(10006,0.,0,0.9), "mltop" : TColor(10005,0,0,1)}
    fcolors = {"leptons" : TColor(20007, 0., 1.0, 0.), "bjet" : TColor(20004,1., 0., 0.), "jet": TColor(20003,1,0.5,0.5), "etmiss" : TColor(20006,0.,0,0.9), "mltop" : TColor(20005,0,0,0)}

    ecol = []
    fcol = []
    for x in ecolors :
      ecol.append(ecolors[x])
      fcol.append(fcolors[x])

    import os
    if not os.path.exists(imageDir): os.makedirs(imageDir)
    image_name = imageDir+"/"+str(event)+".jpg"

    size = 224
    c1 = TCanvas("c1", "c1", size, size)
    c1.Range(-4.5,-math.pi,4.5,math.pi);
    c1.SetCanvasSize(size,size);

    jets = []
    # Represent Jets
    for jet in goodBJets :
        scalePt = 1.5*histo_bin.GetXaxis().FindBin(jet.Pt())

        elj = DrawObjectROOT(jet, scalePt, "bjet")
        jets.append(elj)
        jets[-1].Draw()

    # Represent Jets
    for jet in goodJets :
        scalePt = 1.5*histo_bin.GetXaxis().FindBin(jet.Pt())

        elj = DrawObjectROOT(jet, scalePt, "jet")
        jets.append(elj)
        jets[-1].Draw()

    scalePt = 1.5*histo_bin.GetXaxis().FindBin(etmiss.Pt())
    elmet = DrawObjectROOT(etmiss, scalePt, "etmiss")
    elmet.Draw()


    # Represent Leptons
    scalePt = 1.5*histo_bin.GetXaxis().FindBin(Leptons[0].Pt())
    ell = DrawObjectROOT(Leptons[0], scalePt, "leptons")
    ell.Draw()

    #'event_numEvent.jpg'
    img = TASImage()
    img.FromPad(c1);
    img.SetImageQuality(3)
    img.SetImageCompression(50)
    img.WriteImage(image_name);
Пример #5
0
def getColor(color, transparency = None):
	from ROOT import TColor
	try:
	  color = TColor.GetColor( *color )
	except:
	  if type(color) is not int: color = TColor.GetColor( color )
	if transparency is not None:
	  color = TColor.GetColorTransparent( color, transparency )
	return color
Пример #6
0
 def add_2P2F_hist(self, estimateZX_Data_file):
     file2p2f = ROOT.TFile(estimateZX_Data_file, "READ")
     histname = f"h1D_m4l_Add_{self.get_cr_fs_str()}"
     histPlot2p2f = file2p2f.Get(histname)
     print(f"2P2F contribution = {histPlot2p2f.Integral()}") 
     print("Adding ZZ and WZ to the 2P2F CR in 3P1F")
     histPlot2p2f.Add(self.hist_ls[1])  # This is sloppy. Fix later.
     histPlot2p2f.Add(self.hist_ls[2])
     histPlot2p2f.SetFillColor(TColor.GetColor("#ffffff"))  # White.
     histPlot2p2f.SetLineColor(TColor.GetColor("#ff00ff"))  # Pink.
     histPlot2p2f.SetLineWidth(2)
     histPlot2p2f.SetFillStyle(4000)
     histPlot2p2f.Smooth()
     histPlot2p2f.Draw("hist E1 same goff")
Пример #7
0
def set_palette(name="gray", ncontours=999):
    """Set a color palette from a given RGB list
    stops, red, green and blue should all be lists of the same length
    see set_decent_colors for an example"""

    if name == "gray" or name == "grayscale":
        stops = [0.00, 0.34, 0.61, 0.84, 1.00]
        red = [1.00, 0.84, 0.61, 0.34, 0.00]
        green = [1.00, 0.84, 0.61, 0.34, 0.00]
        blue = [1.00, 0.84, 0.61, 0.34, 0.00]
    # elif name == "whatever":
    # (define more palettes)
    else:
        # default palette, looks cool
        stops = [0.00, 0.34, 0.61, 0.84, 0.1]
        red = [0.00, 0.00, 0.87, 1.00, 0.51]
        green = [0.00, 0.81, 1.00, 0.20, 0.00]
        blue = [0.51, 1.00, 0.12, 0.00, 0.00]

    s = array('d', stops)
    r = array('d', red)
    g = array('d', green)
    b = array('d', blue)

    npoints = len(s)
    TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
    gStyle.SetNumberContours(ncontours)
Пример #8
0
def BPalette():
    r = array([0., 0.0, 1.0, 1.0, 1.0])
    b = array([0., 1.0, 0.0, 0.0, 1.0])
    g = array([0., 0.0, 0.0, 1.0, 1.0])
    stop = array([0., .25, .50, .75, 1.0])
    TColor.CreateGradientColorTable(5, stop, r, g, b, 100)
    return
Пример #9
0
def efficiencyPalette():

    from ROOT import TColor

    pcol = []

    for iBin in range(0, 100):

        rgb = []

        if iBin < 70:
            rgb = [0.70 + 0.007 * iBin, 0.00 + 0.0069 * iBin, 0.00]

        elif iBin < 90:
            rgb = [
                0.70 + 0.007 * iBin,
                0.00 + 0.0069 * iBin + 0.10 + 0.01 * (iBin - 70), 0.00
            ]

        else:
            rgb = [0.98 - 0.098 * (iBin - 90), 0.80, 0.00]

        pcol.append(TColor.GetColor(rgb[0], rgb[1], rgb[2]))

    return pcol
Пример #10
0
def GrayPalette():
    R = array([0., 1.])
    G = array([0., 1.])
    B = array([0., 1.])
    Stop = array([0., 1.])
    TColor.CreateGradientColorTable(2, Stop, R, G, B, 100)
    return
def main(filename, canvases):
    f = TFile(filename, "READ")
    f.ls()
    cols = ["#e41a1c", "#377eb8", "#4daf4a"]
    cols = [TColor.GetColor(i) for i in cols]
    print("Canvases", canvases)
    canname = canvases[0]
    canname.split("_folder_")[-1]
    can = f.Get(canname)
    lcan = can.GetListOfPrimitives()
    lcan.FindObject("TPave").SetHeader("")
    can.Draw()
    print(can)
    # leg = TLegend(0.7, 0.7, 0.9, 0.9)
    for i in canvases[1:]:
        print("Getting", i)
        c = f.Get(i)
        lp = c.GetListOfPrimitives()
        # lp.ls()
        for j in lp:
            if "TH1" not in j.ClassName():
                continue
            print(j)
            can.cd()
            j.Draw("sameHIST")
            can.Update()
    return can
Пример #12
0
    def set2DStyle(self, opt="BasicRainBow"):

        gStyle.SetPadRightMargin(
            0.2
        )  # Leave more space to the right side of the current Pad to show the histogram scale

        if opt == "FancyRainBow":
            icol = 0
            gStyle.SetFrameBorderMode(icol)
            gStyle.SetFrameFillColor(icol)
            gStyle.SetCanvasBorderMode(icol)
            gStyle.SetCanvasColor(icol)
            gStyle.SetPadBorderMode(icol)
            gStyle.SetPadColor(icol)
            gStyle.SetStatColor(icol)
            gStyle.SetOptTitle(0)
            gStyle.SetOptStat(0)
            gStyle.SetOptFit(0)

            ncontours = 999

            s = array.array('d', [0.00, 0.34, 0.61, 0.84, 1.00])
            r = array.array('d', [0.00, 0.00, 0.87, 1.00, 0.51])
            g = array.array('d', [0.00, 0.81, 1.00, 0.20, 0.00])
            b = array.array('d', [0.51, 1.00, 0.12, 0.00, 0.00])

            npoints = len(s)
            TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
            gStyle.SetNumberContours(ncontours)

        if opt == "BasicRainBow":
            gStyle.SetPalette(
                1
            )  # This resets the color palette to a simple Rainbow Color Map w/ 50 colors. See https://root.cern.ch/doc/master/classTColor.html
Пример #13
0
    def color_loader(self, palette, key=''):
        from ROOT import TColor
        import seaborn as sns

        colors = sns.color_palette(palette)

        if key not in self.tcolor_dict:
            self.tcolor_dict[key] = [TColor(*rgb) for rgb in colors]
            colors = self.color_dict[key] = [
                tcolor.GetNumber() for tcolor in self.tcolor_dict[key]
            ]
        else:
            colors = self.color_dict[key]

        color_it = iter(colors)

        centrality_colors = {}

        def centrality_color(cent):
            cent = cent.rstrip('%')
            centparts = cent.split('-') if '-' in cent else cent.split('_')
            cent_key = tuple('%g' % float(f) for f in centparts)
            if cent_key not in centrality_colors:
                centrality_colors[cent_key] = next(color_it)
            return centrality_colors[cent_key]

        return centrality_color
Пример #14
0
def main(input_files, tags, show=True):
    g = []
    for i, j in enumerate(input_files):
        t = tags[i]
        # print(i, j, t)
        g.append(make_reso(j, t, show))
    can = TCanvas("all", "all")
    can.DrawFrame(
        0,
        0,
        1,
        200,
        f";{g[0].GetXaxis().GetTitle()};Resolution {g[0].GetYaxis().GetTitle()};",
    )
    cols = ["#e41a1c", "#377eb8", "#4daf4a", "#984ea3"]
    leg = TLegend(0.9, 0.1, 1, 0.9)
    for j, i in enumerate(g):
        print("Drawing", i)
        c = TColor.GetColor(cols[j])
        i.SetLineColor(c)
        i.SetLineWidth(2)
        leg.AddEntry(i, "", "l")
        i.Draw("sameL")
    leg.Draw()
    can.Update()
    input("press enter to continue")
Пример #15
0
    def make_hstack(self):
        """Return a THStack with a TH1 already set to it."""
        h_stack = ROOT.THStack(self.get_cr_fs_str(), self.get_cr_fs_str())
        h_addtostack = ROOT.TH1F(
            f"h_addtostack_{self.get_cr_fs_str()}",  # Internal name.
            self.get_cr_fs_str(title_friendly=True), # Title.
            100, 0, 2000)
        h_addtostack.SetMinimum(-5.608576)
        h_addtostack.SetMaximum(51.10072)
        h_addtostack.SetDirectory(0)
        h_addtostack.SetStats(0)
        h_addtostack.SetLineColor(TColor.GetColor("#000099"))
        h_addtostack.SetLineStyle(0)
        h_addtostack.SetMarkerStyle(20)  # Black data points.
        h_addtostack.GetXaxis().SetLabelFont(42)
        h_addtostack.GetXaxis().SetLabelOffset(0.007)
        h_addtostack.GetXaxis().SetLabelSize(0.05)
        h_addtostack.GetXaxis().SetTitleSize(0.06)
        h_addtostack.GetXaxis().SetTitleOffset(0.9)
        h_addtostack.GetXaxis().SetTitleFont(42)
        h_addtostack.GetYaxis().SetLabelFont(42)
        h_addtostack.GetYaxis().SetLabelOffset(0.007)
        h_addtostack.GetYaxis().SetLabelSize(0.05)
        h_addtostack.GetYaxis().SetTitleSize(0.06)
        h_addtostack.GetYaxis().SetTitleOffset(1.25)
        h_addtostack.GetYaxis().SetTitleFont(42)
        h_addtostack.GetZaxis().SetLabelFont(42)
        h_addtostack.GetZaxis().SetLabelOffset(0.007)
        h_addtostack.GetZaxis().SetLabelSize(0.05)
        h_addtostack.GetZaxis().SetTitleSize(0.06)
        h_addtostack.GetZaxis().SetTitleFont(42)

        h_stack.SetHistogram(h_addtostack)
        return h_stack
Пример #16
0
def add_palette(palette):
    tcolor_list = []
    for rgb_triplet in palette:
        root_index = TColor.GetColor(rgb_triplet[0], rgb_triplet[1],
                                     rgb_triplet[2])
        tcolor_list.append(root_index)
    return tcolor_list
Пример #17
0
    def __init__(self,
                 files,
                 tree,
                 label,
                 sample_type='undef',
                 friends=(),
                 line_color=1,
                 fill_color=0,
                 marker_style=None,
                 metadata={}):
        """Initializes a new instance of the Process class.

        Args:
            files: An iterable of ROOT file paths for files representing the
                process
            tree: The ROOT TTree path within the files to use
            label: The ROOT TLatex label string to use when rendering the
                process
            line_color: The ROOT TColor number or hex string (#rrggbb) to use
                as the line color when rendering the process
            fill_color: The ROOT TColor number or hex string (#rrggbb) to use
                as the fill color when rendering the process
            marker_style: The ROOT TMarker number to use as the marker style
                when rendering the process
            metadata: A (pickleable) object containing optional metadata
        """
        # Store parameters
        self._files = tuple(files)
        self._files_size_time = None
        self._tree = tree
        self._label = label
        self._sample_type = sample_type
        self._friends = friends
        self._line_color = line_color
        self._fill_color = fill_color
        self._marker_style = marker_style
        self._metadata = metadata

        # Translate hex colors if necessary
        if isinstance(self._line_color, string_types):
            self._line_color = TColor.GetColor(self._line_color)
        if isinstance(self._fill_color, string_types):
            self._fill_color = TColor.GetColor(self._fill_color)

        # Create initial patches container
        self._patches = ()
Пример #18
0
    def get_hist(self, sample_dct, Nickname):
        """Return hist from infile. If hist is MC, make it pretty."""
        # infile = sample_dct[Nickname]["filepath"]
        # isData = sample_dct[Nickname]["isData"]
        f = ROOT.TFile(infile, "READ")

        histname = f"h1D_mass4l_{self.get_cr_fs_str()}"
        if len(self.finalstate) == 0:
            histname += "_inclus"
        hist = f.Get(histname).Clone()
        hist.SetDirectory(0)
        lastbin = hist.GetNbinsX()
        lowedgelastbin = hist.GetBinLowEdge(lastbin)
        highedge = lowedgelastbin + hist.GetBinWidth(lastbin)
        print(f"Low_xbin={hist.GetBinLowEdge(1)}, High_xbin={highedge}") 

        if not isData:
            fillcolor = sample_dct[Nickname]["fillcolor"]
            linecolor = sample_dct[Nickname]["linecolor"]
            hist.SetFillColor(TColor.GetColor(fillcolor))
            hist.SetLineColor(TColor.GetColor(linecolor))
            hist.SetFillStyle(1001)
            hist.SetLineStyle(0)
            hist.SetMarkerStyle(20)
            # x axis.
            hist.GetXaxis().SetLabelFont(42)
            hist.GetXaxis().SetLabelOffset(0.007)
            hist.GetXaxis().SetLabelSize(0.05)
            hist.GetXaxis().SetTitleSize(0.06)
            hist.GetXaxis().SetTitleOffset(0.9)
            hist.GetXaxis().SetTitleFont(42)
            # y axis.
            hist.GetYaxis().SetLabelFont(42)
            hist.GetYaxis().SetLabelOffset(0.007)
            hist.GetYaxis().SetLabelSize(0.05)
            hist.GetYaxis().SetTitleSize(0.06)
            hist.GetYaxis().SetTitleOffset(1.25)
            hist.GetYaxis().SetTitleFont(42)
            # z axis.
            hist.GetZaxis().SetLabelFont(42)
            hist.GetZaxis().SetLabelOffset(0.007)
            hist.GetZaxis().SetLabelSize(0.05)
            hist.GetZaxis().SetTitleSize(0.06)
            hist.GetZaxis().SetTitleFont(42)
        f.Close()
        return hist
Пример #19
0
def getHistColor(index):
    if index == 0: return TColor.GetColor("#000075")
    if index == 1: return TColor.GetColor("#800000")
    if index == 2: return TColor.GetColor("#f58231")
    if index == 3: return TColor.GetColor("#3cb44d")
    if index == 4: return TColor.GetColor("#ffe119")
    if index == 5: return TColor.GetColor("#87F1FF")
    if index == 6: return TColor.GetColor("#F4F1BB")
Пример #20
0
def rgb(r, g, b):
    '''rgb(r, g, b):

    from:
    http://webhome.phy.duke.edu/~dmb60/the-guide/
    TColor* color = gROOT->GetColor(TColor::GetColor(red,green,blue));//Use ints from 0 to 255 
    color->SetAlpha(0.5);//0 is fully transparent, 1 fully opaque
    hist->SetFillColor(color->GetNumber());
    '''
    return TColor.GetColor(r, g, b)
Пример #21
0
def set_h2_color_style():
    n_rgb = 5
    n_contour = 255
    stops = np.array([0.00, 0.34, 0.61, 0.84, 1.00])
    reds = np.array([0.00, 0.00, 0.87, 1.00, 0.51])
    greens = np.array([0.00, 0.81, 1.00, 0.20, 0.00])
    blues = np.array([0.51, 1.00, 0.12, 0.00, 0.00])
    TColor.CreateGradientColorTable(n_rgb, stops, reds, greens, blues,
                                    n_contour)
    gStyle.SetNumberContours(n_contour)
    gPad.SetRightMargin(0.2)
Пример #22
0
def set_palette(name="palette", n=100, ncontours=999):
    """Set a color palette from a given RGB list
    stops, red, green and blue should all be lists of the same length
    see set_decent_colors for an example"""

    if name == "gray" or name == "grayscale":
        stops = [0.00, 0.34, 0.61, 0.84, 1.00]
        red = [1.00, 0.84, 0.61, 0.34, 0.00]
        green = [1.00, 0.84, 0.61, 0.34, 0.00]
        blue = [1.00, 0.84, 0.61, 0.34, 0.00]
    elif name == "myPalette":
        # (define more palettes)
        stops = range(n)
        stops = [-3 + float(i) / n for i in stops]
        Cb = 0.4
        Cr = 0.6
        blue = [-1 / Cb * i + 1 for i in stops]
        green = stops
        red = [1 / (1 - Cr) * i for i in stops]
        for i in range(len(stops)):
            if stops[i] < Cb:
                green[i] = 0
                red[i] = 0
            if stops[i] > Cb and stops[i] < Cr:
                blue[i] = 0
                red[i] = 0
                if stops[i] < 0.5:
                    green[i] = stops[i] / (0.5 - Cb)
                else:
                    green[i] = stops[i] / (0.5 - Cr)
            if stops[i] > Cr:
                green[i] = 0
                blue[i] = 0


#        stops = [0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.00]
#        red   = [0.00, 0.00, 0.00, 0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 1.00]
#        green = [0.00, 0.10, 0.30, 0.60, 0.80, 0.60, 0.40, 0.20, 0.00, 0.00, 0.00]
#        blue  = [0.50, 0.60, 0.70, 0.80, 0.50, 0.30, 0.00, 0.00, 0.00, 0.00, 0.00]
    else:
        # default palette, looks cool
        stops = [0.00, 0.34, 0.61, 0.84, 1.00]
        red = [0.00, 0.00, 0.87, 1.00, 0.51]
        green = [0.00, 0.81, 1.00, 0.20, 0.00]
        blue = [0.51, 1.00, 0.12, 0.00, 0.00]

    s = array('d', stops)
    r = array('d', red)
    g = array('d', green)
    b = array('d', blue)

    npoints = len(s)
    TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
    gStyle.SetNumberContours(ncontours)
Пример #23
0
def defineColors(color_code='ColorCombo424'):
    colors = {}
    rgb = 255.
    for color_number in color_codes[color_code]:
        colors[color_number] = TColor(
            color_number,
            color_codes[color_code][color_number][0] / rgb,
            color_codes[color_code][color_number][1] / rgb,
            color_codes[color_code][color_number][2] / rgb,
        )
    return colors
Пример #24
0
def setColorPalette():
	nGradients = 100
	palette = []
	r = [0, 0/255., 227./255., 255/255., 244/255.]
	g = [0,0/255.,0/255.,237/255.,244/255.]
	b = [0,159/255.,102/255.,0/255.,244/255.]
	stop = [0,.25,.55,.9,1]
	FI = TColor.CreateGradientColorTable(5,array('d',stop),array('d',r),array('d',g),array('d',b),nGradients)
	for i in range(0,nGradients):
		palette.append(FI+i)
	gStyle.SetPalette(nGradients,array('i',palette))
Пример #25
0
def kBird():
    red = array('d', [
        0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764
    ])
    green = array('d', [
        0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832
    ])
    blue = array('d', [
        0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539
    ])
    stops = array('d', [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0])
    TColor.CreateGradientColorTable(9, stops, red, green, blue, 255)
Пример #26
0
def getLineColor(index):
    if index == 3: return TColor.GetColor("#000000")
    if index == 4: return TColor.GetColor("#e6194B")
    if index == 5: return TColor.GetColor("#4363d8")
    if index == 0: return TColor.GetColor("#B9BAA3")
    if index == 1: return TColor.GetColor("#685762")
    if index == 2: return TColor.GetColor("#E8C547")
Пример #27
0
def getStackColor(index):
    if index == 0: return TColor.GetColor("#4C5760")
    if index == 1: return TColor.GetColor("#93A8AC")
    if index == 2: return TColor.GetColor("#D7CEB2")
    if index == 3: return TColor.GetColor("#F4FDD9")
    if index == 4: return TColor.GetColor("#AA767C")
    if index == 5: return TColor.GetColor("#D6A184")
Пример #28
0
def setpalette(name="rainbow", ncontours=99):
    """.. function::setpalette()
    
    Set a color palette from a given RGB list
    stops, red, green and blue should all be lists 
    of the same length 
    see set_decent_colors for an example"""
    from ROOT import TColor, gStyle
    from array import array

    if name == "gray" or name == "grayscale":
        stops = [0.00, 0.34, 0.61, 0.84, 1.00]
        red = [1.00, 0.84, 0.61, 0.34, 0.00]
        green = [1.00, 0.84, 0.61, 0.34, 0.00]
        blue = [1.00, 0.84, 0.61, 0.34, 0.00]
    elif name == 'darkbody':
        stops = [0.00, 0.25, 0.50, 0.75, 1.00]
        red = [0.00, 0.50, 1.00, 1.00, 1.00]
        green = [0.00, 0.00, 0.55, 1.00, 1.00]
        blue = [0.00, 0.00, 0.00, 0.00, 1.00]
    elif name == 'inv_darkbody':
        stops = [0.00, 0.25, 0.50, 0.75, 1.00]
        red = [1.00, 1.00, 1.00, 0.50, 0.00]
        green = [1.00, 1.00, 0.55, 0.00, 0.00]
        blue = [1.00, 0.00, 0.00, 0.00, 0.00]
    elif name == 'deepsea':
        stops = [0.00, 0.34, 0.61, 0.84, 1.00]
        red = [0.00, 0.09, 0.18, 0.09, 0.00]
        green = [0.01, 0.02, 0.39, 0.68, 0.97]
        blue = [0.17, 0.39, 0.62, 0.79, 0.97]
    elif name == 'forest':
        stops = [0.00, 0.25, 0.50, 0.75, 1.00]
        red = [0.93, 0.70, 0.40, 0.17, 0.00]
        green = [0.97, 0.89, 0.76, 0.64, 0.43]
        blue = [0.98, 0.89, 0.64, 0.37, 0.17]
    else:
        # default palette, looks cool
        stops = [0.00, 0.34, 0.61, 0.84, 1.00]
        red = [0.00, 0.00, 0.87, 1.00, 0.51]
        green = [0.00, 0.81, 1.00, 0.20, 0.00]
        blue = [0.51, 1.00, 0.12, 0.00, 0.00]

    s = array('d', stops)
    r = array('d', red)
    g = array('d', green)
    b = array('d', blue)

    npoints = len(s)
    TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
    gStyle.SetNumberContours(ncontours)
Пример #29
0
def style_histogram(drawable,
                    line_color,
                    fill_color,
                    marker_style,
                    fill_style=1001,
                    marker_size=2,
                    line_size=2):
    """Applies a style to a drawable object.

    Args:
        drawable: The object to style
        line_color, fill_color, marker_style: The style to apply
    """

    # Translate hex colors if necessary
    if isinstance(line_color, string_types):
        line_color = TColor.GetColor(line_color)
    if isinstance(fill_color, string_types):
        fill_color = TColor.GetColor(fill_color)

    # Set line color and width
    drawable.SetLineColor(line_color)
    drawable.SetLineWidth(line_size)

    # Set fill style and color
    drawable.SetFillStyle(fill_style)
    drawable.SetFillColor(fill_color)

    # Set marker style
    if marker_style is not None:
        drawable.SetMarkerStyle(marker_style)
        drawable.SetMarkerSize(marker_size)
        drawable.SetMarkerColor(line_color)
    else:
        # HACK: Set marker style to an invalid value if not specified,
        # because we need some way to differentiate rendering in the legend
        drawable.SetMarkerStyle(0)
Пример #30
0
def style_line(drawable, line_color, line_style, line_size=1):
    """Applies a style to a drawable with TAttLine capabilities.

    Args:
        drawable: The object to style
        line_color, line_style, line_size: The style to apply
    """

    # Translate hex colors if necessary
    if isinstance(line_color, string_types):
        line_color = TColor.GetColor(line_color)

    # Set line style, color, and width
    drawable.SetLineColor(line_color)
    drawable.SetLineStyle(line_style)
    drawable.SetLineWidth(line_size)