Home | News | Documentation | Download

Trouble setting logarithmic axis scale

Hello,

I am trying to create a scatterplot using pyroot where the y-axis is logarithmically scaled. The first and second columns of the efficiencies array are the data in question and we want to plot 1/efficiencies[1] vs. efficiencies[0]. For some reason, running this code gives the proper scatterplot but without the log scale. The y axis remains scaled linearly. Is there any workaround for this? Perhaps to create the log scale differently?

import numpy as np
import matplotlib.pyplot as plt
import sys

from ROOT import TCanvas, TFormula, TF1, TH1F, TH2F, TVectorF, TLegend, TH1, TPaveStats, TGraph
from ROOT import gROOT, gObjectTable, gStyle, TPad


def cleaner(inputarray):
    effsonly = inputarray[:, [0,1]]
    cleaned = [pair for pair in effsonly if pair[0] >= 1e-5]
    cleaned = np.asarray(cleaned)
    sigeff = cleaned[:,1]
    bgeffnon0 = cleaned[:,0]
    sig = np.array(sigeff)
    bg = np.array(1.0/bgeffnon0)
    return bg, sig


folder = "myfolder"

efficiencies = np.genfromtxt(folder + "AE_latent/totalROC.csv",delimiter=',')
bgeff, sigeff = cleaner(efficiencies)

scatter = TGraph(len(bgeff), bgeff, sigeff)
scatter.SetMarkerStyle(20)
scatter.SetMarkerSize(0.85)
scatter.SetMarkerColor(4)

scatter.SetTitle("ROC curves")
scatter.GetXaxis().SetTitle("Gluino Efficiency")
scatter.GetXaxis().CenterTitle()
scatter.GetYaxis().SetTitle("1/QCD Efficiency")
scatter.GetYaxis().CenterTitle()


legend = TLegend(0,0.3,0.4,0.7)
legend.SetTextFont(60)
legend.SetHeader("Legend","C")
legend.AddEntry(scatter, "ROC curve in question")
legend.SetEntrySeparation(0)


c4 = TCanvas ('c4', 'ROC')
c4.Divide(2,1)
c4.SetCanvasSize(1500, 750)
c4.cd(2)
legend.Draw()
c4.Update()
c4.cd(1)
scatter.Draw("AP")
c4.SetLogy()
c4.Update()
c4.Draw()

Try SetLogy on the pad, something like

   c4->cd(1);
   gPad->SetLogy();
   scatter->Draw("AP");