p = biggles.Table(1, 3) p[0, 0] = biggles.FramedPlot() p[0, 0].add(biggles.LineX(1.216, linetype="longdashed", linecolor="black")) p[0, 0].add(biggles.LineX(1.216 + 0.027, linetype="dotted", linecolor="black")) p[0, 0].add(biggles.LineX(1.216 - 0.027, linetype="dotted", linecolor="black")) p[0, 0].add(biggles.LineY(0.5)) p[0, 0].add( biggles.PlotLabel(0.1, 0.95, r"$\Upsilon(1S)$", texthalign="left", textvalign="top", fontsize=5.)) x, y, yerr1, yerr2 = fillemup(g1) p[0, 0].add(biggles.Points(y, x, symboltype="filled circle", symbolsize=1.5)) p[0, 0].add(biggles.SymmetricErrorBarsX(y, x, yerr1)) p[0, 0].add(biggles.SymmetricErrorBarsX(y, x, yerr2)) x, y, yerr1, yerr2 = fillemup_mine(g1) p[0, 0].add( biggles.Points(y, x, symboltype="filled circle", symbolsize=1.5, color="red")) p[0, 0].add(biggles.SymmetricErrorBarsX(y, x, yerr1, color="red")) p[0, 0].add(biggles.SymmetricErrorBarsX(y, x, yerr2, color="red")) p[0, 0].x.range = 0.7, 1.7 p[0, 0].y.range = -0.5, len(names) - 0.5 p[0, 0].y.draw_ticks = 0 p[0, 0].y.draw_ticklabels = 0 p[0, 0].frame.ticklabels_style["fontsize"] = 3.5
p = biggles.FramedPlot() xf = Numeric.arange(9460-5, 9460+5, 0.025) yf = map(lambda xi: u1func(318.5185, 3.78739, 0.40577*nbish2nb, 0.053, 0.01864, 0., 0.0267, 0.2, 0., 0.0792, xi), xf) p.add(biggles.Curve(xf, yf)) x = []; y = []; dy = []; dx = []; lab = [] for s in u1runs: x.append(ggdata[s][0]*2000. + u1shifts[s][0]) y.append(ggdata[s][1]) dy.append(ggdata[s][2]) dx.append(u1shifts[s][1]) lab.append(s) p.add(biggles.Points(x, y, symboltype="filled circle", symbolsize=1)) p.add(biggles.SymmetricErrorBarsX(x, y, dx)) p.add(biggles.SymmetricErrorBarsY(x, y, dy)) # x = []; y = []; dy = []; dx = []; lab = [] # for s in u1runs: # x.append(bbindata[s][0]*2000. + u1shifts[s][0]) # y.append(bbindata[s][1]) # dy.append(bbindata[s][2]) # dx.append(u1shifts[s][1]) # lab.append(s) # p.add(biggles.Points(x, y, symboltype="filled circle", symbolsize=1, color="blue")) # p.add(biggles.SymmetricErrorBarsX(x, y, dx, color="blue")) # p.add(biggles.SymmetricErrorBarsY(x, y, dy, color="blue")) x = []; y = []; dy = []; dx = []; lab = [] for s in u1runs:
u3outee = [ -3.26950954112, -3.81874447879, -2.69523715354, -2.74889362332, -2.66285796831, -2.70059556893, -2.90842427327 ] u3outee_err = [ 0.154412757067, 0.119568862537, 0.155137761393, 0.160767851983, 0.104925973842, 0.130096282742, 0.145423604825 ] ggrange = Numeric.array(range(0, -len(names1), -1)) + 0.2 ineerange = Numeric.array(range(0, -len(names1), -1)) outeerange = Numeric.array(range(0, -len(names1), -1)) - 0.2 p = biggles.FramedPlot() tmp1 = biggles.Points(u1gg, ggrange, size=1.5, type="filled circle") p.add(tmp1) p.add(biggles.SymmetricErrorBarsX(u1gg, ggrange, u1gg_err)) tmp2 = biggles.Points(u1inee, ineerange, size=2, type="triangle") p.add(tmp2) p.add(biggles.SymmetricErrorBarsX(u1inee, ineerange, u1inee_err)) tmp3 = biggles.Points(u1outee, outeerange, size=2, type="filled inverted triangle") p.add(tmp3) p.add(biggles.SymmetricErrorBarsX(u1outee, outeerange, u1outee_err)) tmp1.label = r"$\gamma\gamma$ luminosity" tmp2.label = r"inner $e^+e^-$" tmp3.label = r"outer $e^+e^-$" p.add(biggles.PlotKey(0.6, 0.7, [tmp1, tmp2, tmp3])) p.yrange = -len(names1), 1 p.y.ticks = ineerange
12.767438367915, 57.6641809947519, ] p = biggles.FramedPlot() p.add(biggles.Points(area1s, chi21s, symboltype="filled circle", symbolsize=1)) p.add( biggles.SymmetricErrorBarsY(area1s, chi21s, chi21s_err, symboltype="filled circle", symbolsize=1)) p.add( biggles.SymmetricErrorBarsX(area1s, chi21s, area1s_err, symboltype="filled circle", symbolsize=1)) for a, c, j in zip(area1s, chi21s, jit1s): a += 0.0005 c += 0.002 if j == 0.01: p.add( biggles.DataLabel(a, c, "0.01 MeV RMS jitter", texthalign="left", textvalign="top")) else: p.add( biggles.DataLabel(a,
def bscatter(xin, yin, show=True, plt=None, **keywords): """ Name: bscatter Purpose: A wrapper to perform a quick scatter plot with biggles. For anything more complex, it is better to use the object oriented interface. Calling Sequence: bscatter(x, y, xerr=None, yerr=None, xrange=None, yrange=None, type='filled circle', color=None, xlabel=None, ylabel=None, label=None, title=None, file=None, xsize=None, ysize=None, aspect_ratio=None, show=True, plt=None) Return value is the used biggles plot object. For overplotting, send an existing biggles plot object in the plt= keyword """ import biggles if plt is None: plt = biggles.FramedPlot() xlog = keywords.get('xlog', False) ylog = keywords.get('ylog', False) else: xlog = plt.xlog ylog = plt.ylog pdict = {} # plot symbol or line type type = keywords.get('type', 'filled circle') xerr = keywords.get('xerr', None) yerr = keywords.get('yerr', None) x = xin y = yin xrng = keywords.get('xrange', None) yrng = keywords.get('yrange', None) # For log, Don't plot points less than zero w = None if xlog and ylog: xrng = get_log_plot_range(x, err=xerr, input_range=xrng) yrng = get_log_plot_range(y, err=yerr, input_range=yrng) w, = numpy.where((x > xrng[0]) & (y > yrng[0])) elif xlog: xrng = get_log_plot_range(x, err=xerr, input_range=xrng) w, = numpy.where(x > xrng[0]) elif ylog: yrng = get_log_plot_range(y, err=yerr, input_range=yrng) w, = numpy.where(y > yrng[0]) if w is not None: if w.size == 0: raise ValueError("no points > 0 for log plot") x = x[w] y = y[w] pkeywords = {} if 'color' in keywords: pkeywords['color'] = keywords['color'] if 'width' in keywords: pkeywords['width'] = keywords['width'] if type in [ "solid", "dotted", "dotdashed", "shortdashed", "longdashed", "dotdotdashed", "dotdotdotdashed" ]: if 'width' in keywords: pkeywords['width'] = keywords['width'] p = biggles.Curve(x, y, type=type, **pkeywords) else: size = keywords.get('size', 1) p = biggles.Points(x, y, type=type, size=size, **pkeywords) label = keywords.get('label', None) if label is not None: p.label = label plt.add(p) pdict['p'] = p # note for log error bars, we start with original points since # the bars may extend above zero even for negative points if yerr is not None: if ylog: pdict['p_yerr'] = add_log_error_bars(plt, 'y', xin, yin, yerr, yrng, **pkeywords) #p_yerr = add_log_error_bars(plt, 'y', xin, yin, yerr, yrng, **pkeywords) else: p_yerr = biggles.SymmetricErrorBarsY(x, y, yerr, **pkeywords) plt.add(p_yerr) pdict['p_yerr'] = p_yerr if xerr is not None: if xlog: pdict['p_xerr'] = add_log_error_bars(plt, 'y', xin, yin, xerr, xrng, **pkeywords) #p_xerr = add_log_error_bars(plt, 'y', xin, yin, xerr, xrng, **pkeywords) else: p_xerr = biggles.SymmetricErrorBarsX(x, y, xerr, **pkeywords) plt.add(p_xerr) pdict['p_xerr'] = p_xerr plt.xlog = xlog plt.ylog = ylog if xrng is not None: plt.xrange = xrng if yrng is not None: plt.yrange = yrng if 'xlabel' in keywords: plt.xlabel = keywords['xlabel'] if 'ylabel' in keywords: plt.ylabel = keywords['ylabel'] if 'title' in keywords: plt.title = keywords['title'] if 'aspect_ratio' in keywords: plt.aspect_ratio = keywords['aspect_ratio'] if 'file' in keywords: fname = keywords['file'] if fname.find('.eps') != -1 or fname.find('.ps') != -1: plt.write_eps(fname) else: xsize = keywords.get('xsize', 512) ysize = keywords.get('ysize', 512) plt.write_image(xsize, ysize, fname) else: if show: plt.show() pdict['plt'] = plt if 'dict' in keywords: if keywords['dict']: return pdict return plt
def bscatter(xin, yin, show=True, plt=None, **keywords): """ Name: bscatter Purpose: A wrapper to perform a quick scatter plot with biggles. For anything more complex, it is better to use the object oriented interface. Calling Sequence: bscatter(x, y, xerr=None, yerr=None, xrange=None, yrange=None, type='filled circle', color=None, xlabel=None, ylabel=None, label=None, title=None, file=None, xsize=None, ysize=None, aspect_ratio=None, show=True, plt=None) Return value is the used biggles plot object. For overplotting, send an existing biggles plot object in the plt= keyword """ import biggles if plt is None: plt = biggles.FramedPlot() xlog = keywords.get("xlog", False) ylog = keywords.get("ylog", False) else: xlog = plt.xlog ylog = plt.ylog pdict = {} # plot symbol or line type type = keywords.get("type", "filled circle") xerr = keywords.get("xerr", None) yerr = keywords.get("yerr", None) x = xin y = yin xrng = keywords.get("xrange", None) yrng = keywords.get("yrange", None) # For log, Don't plot points less than zero w = None if xlog and ylog: xrng = get_log_plot_range(x, err=xerr, input_range=xrng) yrng = get_log_plot_range(y, err=yerr, input_range=yrng) (w, ) = np.where((x > xrng[0]) & (y > yrng[0])) elif xlog: xrng = get_log_plot_range(x, err=xerr, input_range=xrng) (w, ) = np.where(x > xrng[0]) elif ylog: yrng = get_log_plot_range(y, err=yerr, input_range=yrng) (w, ) = np.where(y > yrng[0]) if w is not None: if w.size == 0: raise ValueError("no points > 0 for log plot") x = x[w] y = y[w] pkeywords = {} if "color" in keywords: pkeywords["color"] = keywords["color"] if "width" in keywords: pkeywords["width"] = keywords["width"] if type in [ "solid", "dotted", "dotdashed", "shortdashed", "longdashed", "dotdotdashed", "dotdotdotdashed", ]: if "width" in keywords: pkeywords["width"] = keywords["width"] p = biggles.Curve(x, y, type=type, **pkeywords) else: size = keywords.get("size", 1) p = biggles.Points(x, y, type=type, size=size, **pkeywords) label = keywords.get("label", None) if label is not None: p.label = label plt.add(p) pdict["p"] = p # note for log error bars, we start with original points since # the bars may extend above zero even for negative points if yerr is not None: if ylog: pdict["p_yerr"] = add_log_error_bars(plt, "y", xin, yin, yerr, yrng, **pkeywords) else: p_yerr = biggles.SymmetricErrorBarsY(x, y, yerr, **pkeywords) plt.add(p_yerr) pdict["p_yerr"] = p_yerr if xerr is not None: if xlog: pdict["p_xerr"] = add_log_error_bars(plt, "y", xin, yin, xerr, xrng, **pkeywords) else: p_xerr = biggles.SymmetricErrorBarsX(x, y, xerr, **pkeywords) plt.add(p_xerr) pdict["p_xerr"] = p_xerr plt.xlog = xlog plt.ylog = ylog if xrng is not None: plt.xrange = xrng if yrng is not None: plt.yrange = yrng if "xlabel" in keywords: plt.xlabel = keywords["xlabel"] if "ylabel" in keywords: plt.ylabel = keywords["ylabel"] if "title" in keywords: plt.title = keywords["title"] if "aspect_ratio" in keywords: plt.aspect_ratio = keywords["aspect_ratio"] if "file" in keywords: fname = keywords["file"] if fname.find(".eps") != -1 or fname.find(".ps") != -1: plt.write_eps(fname) else: xsize = keywords.get("xsize", 512) ysize = keywords.get("ysize", 512) plt.write_img(xsize, ysize, fname) else: if show: plt.show() pdict["plt"] = plt if "dict" in keywords: if keywords["dict"]: return pdict return plt
def use_cross_section(csfunc, filename): hads = [] hads_err = [] for r in testsample: c, e = csfunc(r) hads.append(c) hads_err.append(e) hads_center = jt.wmean(zip(hads, hads_err))[0] hads_sigs = [] for r, c, e in zip(testsample, hads, hads_err): hads_sigs.append((c - hads_center) / e) hads_hist = hist.h1(50, -5, 5).fill(hads_sigs).rootn() def gauss(x, a, m, s): return a * math.exp(-(x - m)**2 / 2. / s**2) / math.sqrt( 2. * math.pi) / s chipoints = hads_hist.frame + (hads_hist.frame[1] - hads_hist.frame[0]) / 2. def chi2(a, m, s): c = 0. for i, x in zip(range(len(hads_hist.frame)), chipoints): if hads_hist.errs[i] > 0: c += (hads_hist.vals[i] - gauss(x, a, m, s))**2 / hads_hist.errs[i]**2 return c # def hist_look(a, m, s): # p = hads_hist.plot() # values = [] # for x in chipoints: # values.append(gauss(x, a, m, s)) # p.add(biggles.Curve(chipoints, values)) # p.show() # hist_look(len(testsample)/5., 0, 1) m = Minuit(chi2, start=[len(testsample) / 5., 0, 1]) m.migrad() hist_chi2, hist_params, hist_errors = m.fval, m.values, m.errors ndf = len(filter(lambda x: x > 0, hads_hist.errs)) values = [] for x in chipoints: values.append(gauss(x, *hist_params)) hist_info = [["$\chi^2/ndf$", hist_chi2, "/", ndf], \ ["RMS", hist_params[2], "$\pm$", hist_errors[2]]] p = biggles.Table(2, 1) p[0, 0] = biggles.FramedPlot() p[0, 0].add( biggles.Points(Numeric.array(hads) / hads_center, range(len(testsample)), type="filled circle")) p[0, 0].add( biggles.SymmetricErrorBarsX( Numeric.array(hads) / hads_center, range(len(testsample)), Numeric.array(hads_err) / hads_center)) p[0, 0].y1.draw_ticklabels = 0 p[0, 0].x1.label = "$\propto$ hadronic cross-section" p[0, 0].add(biggles.LineX(1.)) p[0, 0].add(biggles.LineY(41.5, type="dashed")) l, r = 0.8, 1.2 p[0, 0].xrange = l, r p[0, 0].add(biggles.DataLabel(l + 0.15 * (r - l), 41.5 - 7, "db16")) p[0, 0].add(biggles.DataLabel(l + 0.15 * (r - l), 41.5 + 7, "db17")) p[0, 1] = hads_hist.plot() p[0, 1].add(biggles.Curve(chipoints, values)) hist.addinfobox(p[0, 1], hist_info, width=0.8, colwidth=[0.2, 0.09, 0.23], corner=1, numformat="%.2g") p[0, 1].x1.label = "sigmas away from weighted mean" p[0, 1].yrange = 0, 17 p.aspect_ratio = 8.5 / 11. * 4 p.show() p.write_eps(filename)