Beispiel #1
0
    def _render(self, renderer, region):
        # Perform base-class rendering and setup.
        region = Layout._render(self, renderer, region)

        style = self.style
        margin = style.get("margin", 0)

        dx = region[0]
        dy = region[1]

        rows = self.rows
        num_rows = len(rows)
        figures = iter(self.figures)

        sy = region[3] - region[1] - margin * (num_rows - 1)
        for r, row in enumerate(rows):
            r = num_rows - 1 - r
            y0 = dy + sy * r / num_rows + r * margin
            y1 = dy + sy * (r + 1) / num_rows + r * margin
            sx = region[2] - region[0] - margin * (row - 1)
            for c in range(row):
                figure = figures.next()
                if figure is None:
                    continue
                x0 = dx + sx * c / row + c * margin
                x1 = dx + sx * (c + 1) / row + c * margin
                figure._render(renderer, (x0, y0, x1, y1))
Beispiel #2
0
from   hep.fn import enumerate
import hep.hist
import hep.hist.plot
import sys

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

layout = GridLayout(1, 2, border=0.01)

histogram = hep.hist.Histogram1D(
    30, (-1.0, 2.0), "position", "m",
    bin_type=int, error_model="gaussian")
for b, v in enumerate([7, 12, 28, 27, 29, 48, 60, 50, 71, 71, 73, 85,
                       66, 58, 59, 44, 53, 39, 38, 27, 18, 13, 7, 5, 3,
                       2, 0, 0, 0, 0]):
    histogram.setBinContent(b, v)
histogram.setBinContent("underflow", 15)

plot = hep.hist.plot.Plot(
    1,
    histogram,
    bins="skyline",
    errors=True,
    fill_color=Gray(0.7),
    line_color=None)
layout[0, 0] = plot

plot = hep.hist.plot.Plot(
    1,
Beispiel #3
0
    (2 * point, 2 * point, 8 * point, 2 * point),
    (2 * point, 2 * point, 8 * point, 8 * point),
    (2 * point, 2 * point, 2 * point, 2 * point, 8 * point, 2 * point),
    )

thicknesses = (
    0.30 * point,
    0.75 * point,
    1.50 * point,
    3.00 * point
    )

canvas = Canvas((0, 0, 1, 1), aspect=1)
color = Color(0.6, 0, 0.2)

for d, dash in enumerate(dashes):
    y = (len(dashes) - d) / (1 + len(dashes))
    for t, thickness in enumerate(thicknesses):
        x0 = (1 + t * 8) / (8 * len(thicknesses))
        x1 = (7 + t * 8) / (8 * len(thicknesses))
        canvas.append(
            Line(((x0, y), (x1, y)),
                 color=color,
                 thickness=thickness,
                 dash=dash))
size = (0.10, 0.10)
postscript.EPSFile("lines1.eps", size).render(canvas)
metafile.EnhancedMetafile("lines1.emf", size).render(canvas)
window = xwindow.FigureWindow(canvas, size)

if len(sys.argv) > 1:
Beispiel #4
0
table = hep.table.create(table_path, schema)

row = dict([ ("col%03x" % i, i) for i in xrange(1024) ])

for i in xrange(600000):
    row["col000"] = i
    row["col001"] = 2 * i + 1
    table.append(row)
    
del row, table, schema

#-----------------------------------------------------------------------

table = hep.table.open(table_path)

for index, row in enumerate(table):
    if index % 10000 == 0:
        sys.stdout.write("\r%d" % index)
        sys.stdout.flush()
    compare(row["_index"], index)
    compare(row["col000"], index)
    compare(row["col001"], 2 * index + 1)
    compare(row["col1ec"], 492)

sys.stdout.write("\n")

del row, table

#-----------------------------------------------------------------------

os.unlink(table_path)
Beispiel #5
0
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

from   hep.draw import postscript
from   hep.fn import enumerate
from   hep.hist import Histogram1D, Function1D
from   hep.hist import ezplot

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

data = Histogram1D(10, (0.0, 20.0), "energy", "GeV")
for i, v in enumerate((0, 0, 0, 0, 2, 5, 28, 32, 22, 10, )):
    data.setBinContent(i, v)
data.setBinContent("overflow", 2)

reference = Histogram1D(30, (0.0, 30.0), "energy", "GeV")
for i, v in enumerate(
    (0, 0, 0, 0, 0, 0, 1, 0, 1, 5, 13, 41, 100, 156, 177, 197, 148, 95,
     46, 16, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0)):
    reference.setBinContent(i, v)
reference *= 0.10

function1 = Function1D("100 * gaussian(15, 2, E)")
function2 = Function1D("95 * gaussian(14.8, 2.3, E)")

plot = ezplot.present1D(data, reference,
                        functions=(function1, function2),
                        # errors=True,
Beispiel #6
0
import hep.draw.postscript
import hep.draw.xwindow
from   hep.fn import enumerate
import hep.hist
import hep.hist.plot
import sys

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

histogram1 = hep.hist.Histogram1D(
    30, (-1.0, 2.0), "position", "m",
    bin_type=int, error_model="gaussian")
map(lambda (b, v): histogram1.setBinContent(b, v),
    enumerate([7, 12, 28, 27, 29, 48, 60, 50, 71, 71, 73, 85, 66, 58,
               59, 44, 53, 39, 38, 27, 18, 13, 7, 5, 3, 2, 0, 0, 0, 0]))
histogram1.setBinContent("underflow", 15)

histogram2 = hep.hist.Histogram1D(
    30, (-1.0, 2.0), "position", "m",
    bin_type=int, error_model="gaussian")
map(lambda (b, v): histogram2.setBinContent(b, v),
    enumerate([6, 12, 18, 28, 31, 38, 56, 64, 67, 62, 74, 82, 75, 59,
               68, 69, 44, 42, 25, 15, 28, 10, 7, 7, 4, 3, 2, 0, 0, 0]))
histogram2.setBinContent("underflow", 11)

layout = GridLayout(2, 2)

plot = hep.hist.plot.Plot(
    1,
    border=0.01)
Beispiel #7
0
from   hep.draw import *
from   hep.draw import metafile, postscript, xwindow
from   hep.fn import enumerate
import sys

#-----------------------------------------------------------------------
# tests
#-----------------------------------------------------------------------

texts = [
    r"$x^2 + y^2 = z^2$",
    r"$x\ =\ r\ \sin\theta\cos\phi$",
    r"$\Lambda_{a+b} = \Lambda_a\cdot\Lambda_b$",
    r"The result is, $H^\dagger\sim\infty$.",
    r"en--dash, em---dash",
    r"$10-20 GeV/c^2$",
    r"$\Upsilon(4S)\rightarrow B^+B^-$, $B^\pm\rightarrow K_S\pi^0\pi^\pm$",
    ]

canvas = Canvas((0, 0, 1, 1))
for i, text in enumerate(texts):
    y = (len(texts) - i) / (len(texts) + 2)
    canvas.append(Text((0.1, y), text))

postscript.EPSFile("latex1.eps", (0.15, 0.10)).render(canvas)
metafile.EnhancedMetafile("latex1.emf", (0.15, 0.10)).render(canvas)
window = xwindow.FigureWindow(canvas, (0.15, 0.10))

if len(sys.argv) > 1:
    raw_input("hit enter to end: ")