#----------------------------------------------------------------------- # imports #----------------------------------------------------------------------- from hep.draw import postscript from hep.draw import xwindow import hep.hist.function import hep.hist.plot import sys #----------------------------------------------------------------------- # test #----------------------------------------------------------------------- fn = hep.hist.function.Function1D("sin(x) / x") plot = hep.hist.plot.Plot(1, x_axis_range=(-12, 12), overflows=False) plot.append(fn) postscript.EPSFile("plotfn2.eps", (0.20, 0.13)).render(plot) window = xwindow.FigureWindow(plot) if len(sys.argv) > 1: raw_input("hit enter to end> ")
def iplot(*data_args, **kw_args): """Plot with the current style. Sets 'ifig' to the produced 'Plot' object. '*data_args' -- The data to plot. Pass '1' or '2' to make an empty one- or two-dimensional plot. 'normalize' (keyword argument) -- Normalize histograms to this value. 'statistics' (keyword argument) -- If provided, display statistics. The value is a list of statistic names. '**kw_args' -- Additional style attributes with which to override the current style. The style is applied to the new plot object.""" global ifig global istyle global iwin if len(data_args) == 0: # Nothing to do. return # If there is a single numerical positional argument, treat it as # the number of dimensions for an empty plot. if len(data_args) == 1 and isinstance(data_args[0], int): dimensions = data_args[0] if dimensions not in (1, 2): raise ValueError, \ "%d-dimensional plots not supported" % dimensions series_data = [] # Otherwise, interpret positional arguments as data items to plot. else: # Perform some convenience conversions of data objects. series_data = [ _convertDataForPlot(d, **kw_args) for d in data_args ] dimensions = series_data[0].dimensions # Make sure all have the same number of dimensions. for data in series_data[1 :]: if data.dimensions != dimensions: raise ValueError, "data have different dimensionality" # Make sure we have a window to draw to. __setupWindow() # Construct a style, starting with the default style and adding any # unused keyword arguments. statistics = hep.popkey(kw_args, "statistics", None) style = dict(istyle) style.update(kw_args) # Make the new plot. plot = hep.hist.plot.Plot(dimensions, **style) # Add in the data. for data in series_data: plot.append(data) # Show the plot. ishow(plot) if statistics is not None: ifig.append(hep.hist.plot.Statistics(statistics, *series_data))
66, 58, 59, 44, 53, 39, 38, 27, 18, 13, 7, 5, 3, 2, 0, 0, 0, 0]): histogram.setBinContent(b, v - 30) histogram.setBinContent("underflow", -15) layout = GridLayout(3, 3, border=0.01) x_ranges = ((-1, 2), (-2, 0), (0, 1)) y_ranges = ((-30, 70), (-80, -5), (10, 50)) for x in range(3): for y in range(3): plot = hep.hist.plot.Plot( 1, overflows=False, x_axis_range=x_ranges[x], y_axis_range=y_ranges[y]) plot.append(histogram, bins="skyline", errors=True, fill_color=Gray(0.7), line_color=None) layout[x, y] = plot window = hep.draw.xwindow.FigureWindow(layout, (0.3, 0.2)) if len(sys.argv) > 1: raw_input("hit enter to end: ") hep.draw.postscript.EPSFile("plot1d3.eps", window.size).render(layout)
#----------------------------------------------------------------------- # tests #----------------------------------------------------------------------- histogram = hep.hist.Histogram( (10, (0.0, 1.0), "X"), (20, (-1.0, 1.0), "Y"), bin_type=float) for i in range(10000): # Generate a flat distribution. x = random() y = random() * 2 - 1 w = random() * 1.5 - x histogram.accumulate((x, y), w) layout = GridLayout(2, 1) plot = hep.hist.plot.Plot(2, overflows=False) plot.append(histogram) layout[0, 0] = plot plot = hep.hist.plot.Plot(2, overflows=False, z_range=(-10, 20)) plot.append(histogram) layout[1, 0] = plot hep.draw.postscript.EPSFile("plot6.eps", (0.23, 0.1)).render(layout) window = hep.draw.xwindow.FigureWindow(layout, (0.23, 0.1)) if len(sys.argv) > 1: raw_input("hit enter to end: ")
float, name="$m_{ES}$", units="GeV/$c^2$") y_axis = hep.hist.UnevenlyBinnedAxis( (-1, -0.5, 0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 1.0), float, name=r"$\Delta E$", units="GeV") histogram = hep.hist.Histogram(x_axis, y_axis, title="Test Histogram") for i in range(10000): # Generate a flat distribution. m = random() * 5 e = random() * 2 - 1 histogram << (m, e) layout = GridLayout(2, 2) plot = hep.hist.plot.Plot(2, overflows=False) plot.append(histogram, normalize_bin_size=None) layout[0, 0] = plot plot = hep.hist.plot.Plot(2, overflows=False) plot.append(histogram) layout[1, 0] = plot plot = hep.hist.plot.Plot(2, overflows=False) plot.append(histogram, bins="box", normalize_bin_size=None) layout[0, 1] = plot plot = hep.hist.plot.Plot(2, bins="box", overflows=False) plot.append(histogram) layout[1, 1] = plot window = hep.draw.xwindow.FigureWindow(layout, (0.2, 0.2)) if len(sys.argv) > 1: