Hi,
I’m observing a stange issue when trying to plot a contour line, derived from a TH2D, using PyROOT and saving the canvas in PDF. The same issue arises when the canvas is saved to a .C file and executed in CINT, so I do not believe this to be a PyROOT-specific issue.
What I’m attempting to do is create a contour based on a TH2D for which the line has to be shown dashed (line style 7). However, in the resulting PDF (but also eps or png) the line is always shown solid. If the result is saved as .C and executed interactively, the dashes are shown. However, a c->Print() statement in CINT yields the same result.
The code is as follows:
[code]#!/usr/bin/env python
import ROOT
ROOT.gROOT.SetBatch(True)
def DrawContourLine95( leg, hist, text="", linecolor=1, linestyle=7, linewidth=2):
pval = 0.05
signif = ROOT.TMath.NormQuantile(1-pval)
#contour plot
h = ROOT.TH2D(hist)
h.SetContour(1)
h.SetContourLevel(0, signif)
h.SetLineColor( linecolor )
h.SetLineWidth( linewidth )
h.SetLineStyle( linestyle )
ROOT.SetOwnership(h, 0) # see https://root-forum.cern.ch/t/legend-not-drawn-from-function-in-pyroot/2769/1
h.Draw( "samecont3" )
canvas = ROOT.TCanvas(“c1”, “c1”)
f = ROOT.TFile.Open(“data/mSUGRA.merged.Nominal.root”, “READ”)
h = f.Get(“sigp1expclsf”)
h.SetDirectory(0)
f.Close()
DrawContourLine95(None, h, “”, ROOT.kRed, 7, 2)
l = ROOT.TLine(0, 0, 6000, 1000)
l.SetLineStyle(7)
l.Draw(“same”)
canvas.Print(“test.pdf”)[/code]
(Our data is a [0, 6000]x[0, 1000] size TH2D with significance levels.)
The resulting TLine is nicely drawn dashed, but for the contour it doesn’t work. I also observe the same issue for any line style except 3. Is this a known issue?
Kind regards,
Geert-Jan
test.pdf (15.4 KB)