def plotMatrixLabels( matrix, pad=1.0, color='black', offset = 0.03 ): """ memberMat - frame cluster membership matrix offset - label position tweeking -> biggles object """ a = [] ## data dimensions rec, lig = shape( matrix ) ## label positions step = 1. / ( (rec-1) + (pad*2) ) shift = step*pad + array( range(0, rec), 'f' )*step ## iterate over matrix for r in range( rec ): for l in range( lig ): d = matrix[r][l] if type(d)==int or type(d)== float: a += [ biggles.PlotLabel( shift[r]+offset, shift[l]+offset, str(round( d, 1 )), color = color, size = 1 ) ] if type(d)==str: if matrix[r][l] != '0': a += [ biggles.PlotLabel( shift[r]+offset, shift[l]+offset, d, color = color, size = 1 ) ] return a
def contourPlot( data, inverse=0, symbol='filled circle', label=None, maxContour=None ): plots = [] ## get grid lines plots = plotLines( len(data) ) ## get data points cutoffs = [ 0.01, .1, .2, .3, .4, .5, .6, .7, .8, .9 ] if inverse: cutoffs = 1./array([ 15, 10, 8, 6, 5, 4, 3, 2, 1 ]) data = moreDockingInfo( data, levels=cutoffs ) ## callculate symbol size if maxContour: max_data = maxContour*1. else: max_data = max( ravel(data) )*1. max_symbol_size = 15 scale_factor = max_data/(max_symbol_size**2) def scaleCircle( value ): return int(round(sqrt(value/scale_factor))) ## colors col = colorSpectrum( len(cutoffs)) col.reverse() col=['light grey'] + col[1:] label_col = ['dark grey'] + col[1:] range_max = [] range_min = [] for i in range(len(cutoffs)): range_max += [ max( ravel( data[:,:,i] ) ) ] range_min += [ min( ravel( data[:,:,i] ) ) ] for r in range( shape(data)[0] ): for l in range( shape(data)[1] ): plots += [ biggles.Point( r+1, l+1, color=col[i], size=scaleCircle(data[r][l][i]), type=symbol ) ] ## legend plots += [ biggles.PlotLabel( 1.04, .98, 'FNC>', size=2 ) ] for i in range( len(cutoffs) ): if sum( take(data, (i,), 2) )>0: ## plots += [ biggles.PlotLabel( 1.03, .95-i*0.03, str(i*.1), ## color=label_col[i],size=2 ) ] plots += [ biggles.PlotLabel( 1.03, .95-i*0.03, '%.2f'%cutoffs[i], color=label_col[i],size=2 ) ] plots += [ biggles.PlotLabel( 1.03, .35-i*0.02, str(range_min[i])+'-'+str(range_max[i]), color=label_col[i],size=1 ) ] return plots
def show(self, fileName=None): """ Show ramachandran plot. """ plot = biggles.FramedPlot() plot.xrange = (-180., 180.) plot.yrange = (-180., 180.) plot.xlabel = "$\Phi$" plot.ylabel = "$\Psi$" if self.name: plot.title = self.name ## add allowed regions bg_plot = self.ramachandran_background() for p in bg_plot: plot.add(p) ## add ramachandran phi, psi valies points, inset = self.ramachandran() for p in points: plot.add(p) if inset: plot.add(inset) plot.add(biggles.PlotLabel(1.14, 0.55, self.profileName, size=2)) plot.add(biggles.PlotLabel(1.1, 0.45, "GLY star", size=2)) plot.add(biggles.PlotLabel(1.12, 0.40, "PRO square", size=2)) plot.show() if fileName: plot.write_eps(fileName)
def plotKey(data, name, key): ## plot the cluster rmsd dist. plot = biggles.FramedPlot() plot.add(biggles.PlotLabel(0.5, 0.90, name, size=4)) ## customize plot appearence #plot.x1.label = 'cluster' plot.y2.label = 'size' plot.y1.label = key plot.x2.draw_ticks = 0 plot.y2.draw_ticks = 0 ## Plot plot.add( biggles.ErrorBarsY(clst_range, data[key][1], data[key][2], width=1)) plot.add(biggles.Points(clst_range, data[key][0], type='cross', size=1)) plot.add(biggles.LineY(0.25, type='dot')) ## add label with info about 'good' solutions good = [] for clst in clst_range: if data[key][0][clst - 1] > 0.25: good += [clst] plot.add(biggles.PlotLabel(0.5, 0.80, str(good), size=1)) return plot
def test_ColorSpectrum( self ): """ColorSpectrum test""" try: import biskit.tools as T import biggles as B except: B = 0 c_grey = ColorSpectrum( 'grey', 0, 100 ) c_sausage = ColorSpectrum( 'sausage', 0, 100 ) c_plasma = ColorSpectrum( 'plasma', 0, 100 ) c_plasma2 = ColorSpectrum( 'plasma2', 0, 100 ) if B: self.p = B.FramedPlot() ## old_spectrum = T.colorSpectrum( 100 ) self.result = [] for i in range( -1, 100 ): x = (i, i+1 ) if B: self.result += [ c_grey.color( i ) ] self.p.add( B.FillBelow( x, (1., 1.), color = c_grey.color( i ) ) ) self.p.add( B.FillBelow( x, (0.75, 0.75), color = c_sausage.color( i ) ) ) self.p.add( B.FillBelow( x, (0.5, 0.5), color = c_plasma.color( i ) ) ) self.p.add( B.FillBelow( x, (0.25, 0.25), color = c_plasma2.color( i ) ) ) ## self.p.add( B.FillBelow( x, (0., 0.), ## color = old_spectrum[i] )) if B: self.p.add( B.Curve( (0,100), (1.,1.)) ) self.p.add( B.Curve( (0,100), (.75,.75)) ) self.p.add( B.Curve( (0,100), (.5,.5) )) self.p.add( B.Curve( (0,100), (0.25, 0.25)) ) self.p.add( B.Curve( (0,100), (0.0, 0.0)) ) self.p.add( B.PlotLabel( 0.5 ,0.9, 'grey') ) self.p.add( B.PlotLabel( 0.5 ,0.65, 'sausage') ) self.p.add( B.PlotLabel( 0.5 ,0.4, 'plasma') ) self.p.add( B.PlotLabel( 0.5 ,0.15, 'plasma2') ) if (self.local or self.VERBOSITY > 2) and B: self.p.show() ##self.assertEqual(self.result, self.EXPECTED) ## tolerate two differences to account for Python 3 result a = N0.array(self.result) b = N0.array(self.EXPECTED) self.assert_(N0.count_nonzero(a-b)<3)
def plot(complex_lst): ## plot the cluster rmsd dist. plot = biggles.FramedPlot() inset = biggles.FramedPlot() ## plot title plot.title = '/'.join(string.split(absfile(options['o']), '/')[-5:-1]) ## customize plot appearence plot.x1.label = 'cluster' plot.y2.label = 'size' plot.y1.label = 'rmsd' plot.x2.draw_ticks = 0 plot.y2.draw_ticks = 0 inset.frame.draw_ticks = 0 inset.x1.draw_ticklabels = 0 inset.y1.draw_ticklabels = 0 inset.y2.draw_ticklabels = 1 inset.y2.draw_ticks = 1 inset.y2.ticks_style['color'] = 'red' ## get cluter and rmsd lists clst_list = [] rms_list = [] for compl in complex_lst: clst_list += [compl.info['hex_clst']] rms_list += [compl.info['rms']] ## get average, max, min and size of cluster data = [] clst_range = range(1, max(clst_list) + 1) for clst in clst_range: rms = compress(equal(clst_list, clst), rms_list) data += [[average(rms), max(rms), min(rms), len(rms)]] data = transpose(data) ## Inset inset.add(biggles.Curve(clst_range, data[3], color='red')) ## Plot plot.add(biggles.ErrorBarsY(clst_range, data[1], data[2])) plot.add(biggles.Points(clst_range, data[0], type='cross', size=1)) plot.add(biggles.Inset((0.0, 0.0), (1.0, 1.0), inset)) plot.add(biggles.LineY(10, type='dot')) ## add label with info about 'good' solutions (average rmsd < 10A) good = [] for clst in clst_range: if data[0][clst - 1] < 10: good += [clst] plot.add(biggles.PlotLabel(0.5, 0.98, 'Solutions with rmsd < 10A', size=1)) plot.add(biggles.PlotLabel(0.5, 0.95, str(good), size=1)) ## plot and save plot.show() plot.write_eps(string.split(options['o'], '.')[0] + '.eps')
def plotMemberProfiles( self, *name, **arg ): """ Plot profiles of all member trajectories seperately:: plotMemberProfiles( name1, [name2, .. ],[ arg1=x,..]) -> biggles.Table :param name: profile name(s) :type name: str :param arg: pairs for biggles.Curve() and/or xlabel=..,ylabel=.. :type arg: key=value :return: biggles plot object :rtype: biggles.FramedArray() """ if not biggles: raise ImportError('biggles module could not be imported.') rows = self.n_members // 2 + self.n_members % 2 page = biggles.FramedArray( rows , 2) biggles.configure('fontsize_min', 1) colors = T.colorSpectrum( len( name ) , '00FF00', 'FF00FF') ml = self.memberList() i = 0 minV = maxV = None for t in ml: for j in range( len(name)): p = t.profile( name[j] ) if minV is None or minV > min( p ): minV = min(p) if maxV is None or maxV < max( p ): maxV = max(p) page[i//2, i%2].add( biggles.Curve( list(range( len(p))), list(p), color=colors[j], **arg ) ) page[i//2, i%2].add( biggles.PlotLabel( 0.8, 0.8-j/8.0, name[j], color=colors[j]) ) page[i//2, i%2].add( biggles.PlotLabel( 0.1, 0.9, 'Traj %i' % i)) i += 1 if self.n_members % 2 != 0: line = biggles.Line( (0,minV), (len(p),maxV) ) page[ self.n_members//2, 1 ].add( line ) page.uniform_limits = 1 page.xlabel = arg.get('xlabel',None) page.ylabel = arg.get('ylabel',None) return page
def logPlot(data, lenZeros, colorDic, ref=None, ave=None): """ log(fraction of solutions) vs. fraction of native contacts (sorted) data - 3D matrix (rec * lig * soln) lenZeros - integer, the lowest number of zeros on any rec-lig pair ref - tuple, position of reference -> list of plot objects """ ## data dimensions rec, lig, soln = shape(data) ## y data range (removing all zeros region) y = arange(soln - (lenZeros), 0, -1, 'f') / soln plots = [] if type(colorDic) == str: colorDic = {'a': colorDic} ## collect all for r in range(rec): for l in range(lig): dt = data[r][l][-(soln - lenZeros):] if ave: dt = mathUtils.runningAverage(dt, ave, 1) plots += [biggles.Curve(dt, y, color=colorDic['a'])] if ref: nr = ref[0] - 1 nl = ref[1] - 1 ## contains x-ray rec for l in range(lig): dt = data[nr][l][-(soln - lenZeros):] if ave: dt = mathUtils.runningAverage(dt, ave, 1) plots += [biggles.Curve(dt, y, color=colorDic['r'])] ## contains x-ray lig for r in range(rec): dt = data[r][nl][-(soln - lenZeros):] if ave: dt = mathUtils.runningAverage(dt, ave, 1) plots += [biggles.Curve(dt, y, color=colorDic['l'])] ## add ref in other color dt = data[nr][nl][-(soln - lenZeros):] if ave: dt = mathUtils.runningAverage(dt, ave, 1) plots += [biggles.Curve(dt, y, color=colorDic['x'], width=4)] ## labels plots += [biggles.PlotLabel(.8, .95, 'Xray rec', color=colorDic['r'])] plots += [biggles.PlotLabel(.8, .90, 'Xray lig', color=colorDic['l'])] plots += [biggles.PlotLabel(.8, .85, 'Xray', color=colorDic['x'])] return plots
def test_ColorSpectrum( self ): """ColorSpectrum test""" try: import biggles as B except: B = 0 c_grey = ColorSpectrum( 'grey', 0, 100 ) c_sausage = ColorSpectrum( 'sausage', 0, 100 ) c_plasma = ColorSpectrum( 'plasma', 0, 100 ) c_plasma2 = ColorSpectrum( 'plasma2', 0, 100 ) if B: self.p = B.FramedPlot() ## old_spectrum = tools.colorSpectrum( 100 ) self.result = [] for i in range( -1, 100 ): x = (i, i+1 ) if B: self.result += [ c_grey.color( i ) ] self.p.add( B.FillBelow( x, (1., 1.), color = c_grey.color( i ) ) ) self.p.add( B.FillBelow( x, (0.75, 0.75), color = c_sausage.color( i ) ) ) self.p.add( B.FillBelow( x, (0.5, 0.5), color = c_plasma.color( i ) ) ) self.p.add( B.FillBelow( x, (0.25, 0.25), color = c_plasma2.color( i ) ) ) ## self.p.add( B.FillBelow( x, (0., 0.), ## color = old_spectrum[i] )) if B: self.p.add( B.Curve( (0,100), (1.,1.)) ) self.p.add( B.Curve( (0,100), (.75,.75)) ) self.p.add( B.Curve( (0,100), (.5,.5) )) self.p.add( B.Curve( (0,100), (0.25, 0.25)) ) self.p.add( B.Curve( (0,100), (0.0, 0.0)) ) self.p.add( B.PlotLabel( 0.5 ,0.9, 'grey') ) self.p.add( B.PlotLabel( 0.5 ,0.65, 'sausage') ) self.p.add( B.PlotLabel( 0.5 ,0.4, 'plasma') ) self.p.add( B.PlotLabel( 0.5 ,0.15, 'plasma2') ) if (self.local or self.VERBOSITY > 2) and B: self.p.show() self.assertEqual(self.result, self.EXPECTED)
def plot_autocorr(trials, window=100, show=False, **kw): import biggles import emcee arr = biggles.FramedArray(trials.shape[1], 1) arr.uniform_limits = True func = emcee.autocorr.function(trials) tau2 = emcee.autocorr.integrated_time(trials, window=window) xvals = numpy.arange(func.shape[0]) zc = biggles.Curve([0, func.shape[0] - 1], [0, 0]) for i in xrange(trials.shape[1]): pts = biggles.Curve(xvals, func[:, i], color='blue') lab = biggles.PlotLabel(0.9, 0.9, r'$%s tau\times 2: %s$' % (i, tau2[i]), halign='right') arr[i, 0].add(pts, zc, lab) if show: arr.show(**kw) return arr
def plotInfo(info): """ biggles FramedArray with only information labels """ stat = biggles.FramedPlot() #stat.title = 'grouping info' ## turn off drawing of all axis related objects ## note: if all is turned off plotting doesnt work, so make one white stat.x.draw_ticks = 0 stat.y.draw_ticks = 0 stat.x.draw_ticklabels = 0 stat.y.draw_ticklabels = 0 stat.y.draw_spine = 0 stat.x.spine_style['color'] = 'white' ## have to make it a plot - add a white line stat.add(biggles.LineY(0.01, type='dot', color='white')) ## add info lines one by one (from bottom and up!) info = string.split(info, '\n') for l in range(len(info)): yPos = 0.95 - 0.04 * l stat.add( biggles.PlotLabel( .05, yPos, info[l], halign='left', \ size=1, face='courier' ) ) return stat
def plotHistogram( self, *name, **arg ): """ @param bins: number of bins (10) @type bins: int @param ynormalize: normalize histograms to area 1.0 (False) @type ynormalize: bool @param xnormalize: adapt bin range to min and max of all profiles (True) @type xnormalize: bool @param xrange: min and max of bin range (None) @type xrange: (float, float) @param steps: draw histogram steps (True) @type steps: bool """ if not biggles: raise ImportError, 'module biggles could not be imported' plot = biggles.FramedArray( len(name),1 ) if not 'size' in arg: arg['size'] = 1 bins = arg.get('bins', 10) hist = arg.get('ynormalize', False) steps= arg.get('steps', 1) histrange= arg.get('xrange', None) autorange= arg.get('xnormalize', histrange is None) xkey = arg.get('xkey', None) if xkey: plot.xlabel = xkey if autorange: v = [] for keys in name: if not type(keys) is tuple: keys = ( keys, ) for key in keys: v += list(self[key]) histrange = ( min( v ), max( v ) ) for i, keys in enumerate(name): if not type(keys) is tuple: keys = ( keys, ) for j, key in enumerate(keys): h = density( self[key], nBins=bins, steps=steps, hist=hist, range=histrange ) x = h[:,0] y = h[:,1] colors = [0] + T.colorSpectrum( len(keys) , '00FF00', 'FF00FF') plot[i,0].add( biggles.Curve( x, y, color=colors[j], **arg ) ) plot[i,0].add( biggles.PlotLabel( 0.7, 0.95-j*0.1, key, color=colors[j] ) ) return plot
def plotRanking(data, colorDic, ref=(1, 1)): """ log(fraction of solutions) vs. fraction of native contacts (sorted) data - 3D matrix (rec * lig * soln) ref - tuple, position of reference -> list of plot objects """ ## data dimensions rec, lig, soln = shape(data) ## y data range (removing all zeros region) x = arange(1, soln + 1, 1, 'f') / soln area = zeros((rec, lig), 'f') plots = [] ## collect all ref_area = getArea(x, (maxVal(data[ref[0] - 1][ref[1] - 1]))) for r in range(rec): for l in range(lig): d = maxVal(data[r][l]) area[r][l] = getArea(x, d) - ref_area plots += [biggles.Curve(x, d, color=colorDic['a'])] if ref: nr = ref[0] - 1 nl = ref[1] - 1 ## contains x-ray rec for l in range(lig): plots += [ biggles.Curve(x, maxVal(data[nr][l]), color=colorDic['r']) ] ## contains x-ray lig for r in range(rec): plots += [ biggles.Curve(x, maxVal(data[r][nl]), color=colorDic['l']) ] ## add ref in other color plots += [biggles.Curve(x, maxVal(data[nr][nl]), color=colorDic['x'])] ## labels plots += [biggles.PlotLabel(.8, .95, 'Xray rec', color=colorDic['r'])] plots += [biggles.PlotLabel(.8, .90, 'Xray lig', color=colorDic['l'])] plots += [biggles.PlotLabel(.8, .85, 'Xray', color=colorDic['x'])] return plots, area
def plotNrLabels(nr, pos=-0.05, pad=1): """ nr - number of models (usually 1+10) add xy tick labels -> biggles object """ ## label position tweeking step = 1. / ((nr - 1) + (pad * 2)) shift = step * pad + array(range(0, nr), 'f') * step p = [] for c in range(0, nr): p += [biggles.PlotLabel(shift[c], pos, str(c), size=3)] p += [biggles.PlotLabel(pos, shift[c], str(c), size=3)] return p
def plot_line_fit(args, extra, x, y, res, xlabel, ylabel, label_error=True): import biggles plt = biggles.FramedPlot() ymin = y.min() ymax = y.max() if ymin < 0: yr = [1.1 * ymin, 0.0] else: yr = [0, 1.1 * ymax] xr = [0.0, 1.1 * x.max()] plt.xrange = xr plt.yrange = yr plt.xlabel = xlabel plt.ylabel = ylabel plt.aspect_ratio = 1 xfit = np.linspace(0, xr[1]) yfit = res['offset'] + res['slope'] * xfit pts = biggles.Points(x, y, type='filled circle') c = biggles.Curve(xfit, yfit, color='blue') if label_error: alab = r'$slope = %.3g \pm %.3g' % (res['slope'], res['slope_err']) blab = r'$offset = %.3g \pm %.3g' % (res['offset'], res['offset_err']) else: alab = r'$slope = %.3g' % (res['slope'], ) blab = r'$offset = %.3g' % (res['offset'], ) alabel = biggles.PlotLabel(0.9, 0.9, alab, halign='right') blabel = biggles.PlotLabel(0.9, 0.85, blab, halign='right') plt.add(c, pts, alabel, blabel) plotfile = files.get_plot_url(args.runs[0], extra) print("writing:", plotfile) eu.ostools.makedirs_fromfile(plotfile) plt.write_eps(plotfile) if args.show: plt.show()
def plot(self, xkey, *ykey, **arg): """ Plot pairs of item values. The additional arg arguments are handed over to biggles.Points(). The special xkey value 'index' uses the position of each item as x-axis. If only one key is given, it is taken as ykey and the x-axis is the index of each item (xkey='index'). C{ EXAMPLE: plot( xkey, [ykey1, ykey2..],[arg1=x, arg2=y]) } C{ -> biggles.FramedPlot } @param xkey: key for x-values @type xkey: any @param ykey: key for y-values @type ykey: any @param arg: arguments handed over to biggles.Points() @type arg: any @return: Biggles.FramedPlot, display with show() ! @rtype: Biggles.FramedPlot """ if not biggles: raise ImportError, 'biggles module could not be imported.' if len(ykey) == 0: xkey, ykey = 'index', [xkey] plot = biggles.FramedPlot() plot.xlabel = xkey colors = C.colorRange(len(ykey)) if not 'size' in arg: arg['size'] = 1 for i in range(len(ykey)): x = range(len(self)) if xkey != 'index': x = self.valuesOf(xkey) y = self.valuesOf(ykey[i]) x, y = self.__maskNone(x, y) plot.add(biggles.Points(x, y, color=colors[i], **arg)) plot.add( biggles.PlotLabel(0.2, 0.95 - i / 8.0, ykey[i], color=colors[i])) return plot
def plotRmsLabels(nr, rmsd_dic, mask, pad=1): """ nr - number of models (usually 1+10) mask - names of maska to use add rmsd values to plot -> biggles object """ ## label position tweeking step = 1. / ((nr - 1) + (pad * 2)) shift = step * pad + array(range(0, nr), 'f') * step p = [] for c in range(0, nr): m, r, l = getRmsdValues(rmsd_dic, mask) p += [biggles.PlotLabel(shift[c], -0.02, r[c][0], size=1)] p += [biggles.PlotLabel(shift[c], -0.04, r[c][1], size=1)] p += [biggles.PlotLabel(shift[c], -0.09, m[c], size=3)] p += [biggles.PlotLabel(-0.03, shift[c] + 0.01, l[c][0], size=1)] p += [biggles.PlotLabel(-0.03, shift[c] - 0.01, l[c][1], size=1)] p += [biggles.PlotLabel(-0.09, shift[c], m[c], size=3)] return p
def plotArray(self, *name, **arg): """ Plot several profiles as a panel of separate plots. :param *name: one or more profile names or tuples of profile names :type *name: str or (str, str,...) :param xkey: profile to be used as x-axis (default: None) :type xkey: str :param arg: key=value pairs for Biggles.Curve() function :type arg: :return: plot, view using plot.show() :rtype: biggles.FramedPlot :raise TypeError: if profile contains non-number items :raise ImportError: If biggles module could not be imported """ if not biggles: raise ImportError('module biggles could not be imported') plot = biggles.FramedArray(len(name), 1) if not 'size' in arg: arg['size'] = 1 xkey = arg.get('xkey', None) if xkey: plot.xlabel = xkey for i, keys in enumerate(name): if not type(keys) is tuple: keys = (keys, ) for j, key in enumerate(keys): x = self.get(xkey, list(range(self.profLength()))) y = self[key] colors = [0] + T.colorSpectrum(len(keys), '00FF00', 'FF00FF') plot[i, 0].add(biggles.Curve(x, y, color=colors[j], **arg)) plot[i, 0].add( biggles.PlotLabel(0.7, 0.95 - j * 0.1, key, color=colors[j])) return plot
def plotArray(self, xkey, *ykey, **arg): """ Plot pairs of item values. C{ EXAMPLE: plot( xkey, [ykey1, ykey2..],[arg1=x, arg2=y]) } C{ -> biggles.FramedPlot } @param xkey: key for x-values @type xkey: any @param ykey: key for y-values @type ykey: any @param arg: arguments handed over to biggles.Points() @type arg: any @return: Biggles.FramedArray, display with show() @rtype: Biggles.FramedArray """ if not biggles: raise ImportError, 'biggles module could not be imported.' if len(ykey) == 0: xkey, ykey = 'index', [xkey] plot = biggles.FramedArray(len(ykey), 1) plot.xlabel = xkey colors = C.colorRange(len(ykey)) if not 'size' in arg: arg['size'] = 1 for i in range(len(ykey)): x = range(len(self)) if xkey != 'index': x = self.valuesOf(xkey) y = self.valuesOf(ykey[i]) x, y = self.__maskNone(x, y) plot[i, 0].add(biggles.Points(x, y, color=colors[i], **arg)) plot[i, 0].add(biggles.PlotLabel(0.2, 0.95, ykey[i], color=colors[i])) return plot
def __plotSequence(self, list, **arg): """ add curve to current plot, with x1..xn = 0..n and y1..yn = |list| @param list: list to plot @type list: [any] """ if not biggles: raise ImportError, 'biggles module could not be imported.' self.plot.add( biggles.Curve( range( len(list) ), list, **arg ) ) if arg.has_key('label'): self.plot.lastY -= .05 self.plot.add( biggles.PlotLabel( self.plot.lastX, self.plot.lastY, arg['label'], **arg ))
def plot(self, xkey, *ykey, **arg): """ Plot pairs of info values. The additional arg arguments are handed over to biggles.Points().:: plot( xkey, [ykey1, ykey2..],[arg1=x, arg2=y]) -> biggles.FramedPlot @param xkey: key specifying x-values @type xkey: str @param ykey: key specifying y-values @type ykey: str OR [str] @param arg: additional biggles arguments @type arg: key=value @return: biggles plot object @rtype: biggles.FramedPlot() """ if not biggles: raise ImportError('biggles module could not be imported.') plot = biggles.FramedPlot() plot.xlabel = xkey colors = t.colorSpectrum(len(ykey)) if not 'size' in arg: arg['size'] = 1 for i in range(len(ykey)): x = self.valuesOf(xkey) y = self.valuesOf(ykey[i]) x, y = self.__maskNone(x, y) plot.add(biggles.Points(x, y, color=colors[i], **arg)) plot.add( biggles.PlotLabel(0.2, 0.95 - i / 8.0, ykey[i], color=colors[i])) return plot
def plot(self, *name, **arg): """ Plot one or more profiles using Biggles:: plot( name1, [name2, ..],[arg1=x, arg2=y]) -> biggles.FramedPlot :param name: one or more profile names :type name: str :param arg: key=value pairs for Biggles.Curve() function :type arg: :raise TypeError: if profile contains non-number items :return: plot, view using plot.show() :rtype: biggles.FramedPlot :raise ImportError: If biggles module could not be imported """ if not biggles: raise ImportError('module biggles could not be imported') plot = biggles.FramedPlot() colors = T.colorSpectrum(len(name), '00FF00', 'FF00FF') for i in range(len(name)): p = N.array(self.get(name[i])) if p.dtype in ['O', 'c']: raise TypeError('Cannot plot values of profile %s.' % name[i]) # Biggles with its old Numeric cannot handle numpy arrays plot.add( biggles.Curve(list(range(len(p))), list(p), color=colors[i], **arg)) plot.add( biggles.PlotLabel(0.8, 0.8 - i / 8.0, name[i], color=colors[i])) return plot
def test_example3(self): x = numpy.arange(0, 3 * numpy.pi, numpy.pi / 10) y = numpy.sin(x) p = biggles.FramedPlot() p.title = "Title" p.xlabel = "X axis" p.ylabel = "Y axis" p.add(biggles.Histogram(y)) p.add(biggles.PlotLabel(.5, .5, "Histogram", color=0xcc0000)) t1 = biggles.Table(1, 2) t1[0, 0] = p t1[0, 1] = p t2 = biggles.Table(2, 1) t2[0, 0] = t1 t2[1, 0] = p _write_example(3, p)
def subPlot(data, data_keys, x_key, y_key): ## data x_dat = data[keys.index(x_key)] y_dat = data[keys.index(y_key)] print x_key, y_key, keys.index(x_key), keys.index(y_key) ## outline data y_val = [] for v in y_dat: if not v in y_val: y_val += [v] y_val = sort(y_val) x_max = [] x_min = [] for v in y_val: x_sub_dat = compress(v == y_dat, x_dat) x_max += [max(x_sub_dat)] x_min += [min(x_sub_dat)] ## y_val = Biskit.mathUtils.runningAverage( y_val, 3 ) ## x_max = Biskit.mathUtils.runningAverage( x_max, 3 ) ## x_min = Biskit.mathUtils.runningAverage( x_min, 3 ) ## collect plots sp = [] sp += [biggles.Curve(x_max, y_val, color='grey')] sp += [biggles.Curve(x_min, y_val, color='grey')] sp += [biggles.Points(x_dat, y_dat, type='dot', size=1)] sp += [biggles.PlotLabel(.8, .9, y_key, size=3)] return sp
def compare_images_mosaic(im1, im2, **keys): import biggles import copy import images show = keys.get('show', True) ymin = keys.get('min', None) ymax = keys.get('max', None) color1 = keys.get('color1', 'blue') color2 = keys.get('color2', 'orange') colordiff = keys.get('colordiff', 'red') nrow = 2 ncol = 3 label1 = keys.get('label1', 'im1') label2 = keys.get('label2', 'im2') cen = keys.get('cen', None) if cen is None: cen = [(im1.shape[0] - 1) / 2., (im1.shape[1] - 1) / 2.] labelres = '%s-%s' % (label1, label2) biggles.configure('default', 'fontsize_min', 1.) if im1.shape != im2.shape: raise ValueError("images must be the same shape") #resid = im2-im1 resid = im1 - im2 # will only be used if type is contour tab = biggles.Table(2, 1) if 'title' in keys: tab.title = keys['title'] tkeys = copy.deepcopy(keys) tkeys.pop('title', None) tkeys['show'] = False tkeys['file'] = None tkeys['nonlinear'] = None # this has no effect tkeys['min'] = resid.min() tkeys['max'] = resid.max() mosaic = np.zeros((im1.shape[0], 3 * im1.shape[1])) ncols = im1.shape[1] mosaic[:, 0:ncols] = im1 mosaic[:, ncols:2 * ncols] = im2 mosaic[:, 2 * ncols:3 * ncols] = resid residplt = images.view(mosaic, **tkeys) dof = im1.size chi2per = (resid**2).sum() / dof lab = biggles.PlotLabel(0.9, 0.9, r'$\chi^2/npix$: %.3e' % chi2per, color='red', halign='right') residplt.add(lab) cen0 = int(cen[0]) cen1 = int(cen[1]) im1rows = im1[:, cen1] im1cols = im1[cen0, :] im2rows = im2[:, cen1] im2cols = im2[cen0, :] resrows = resid[:, cen1] rescols = resid[cen0, :] him1rows = biggles.Histogram(im1rows, color=color1) him1cols = biggles.Histogram(im1cols, color=color1) him2rows = biggles.Histogram(im2rows, color=color2) him2cols = biggles.Histogram(im2cols, color=color2) hresrows = biggles.Histogram(resrows, color=colordiff) hrescols = biggles.Histogram(rescols, color=colordiff) him1rows.label = label1 him2rows.label = label2 hresrows.label = labelres key = biggles.PlotKey(0.1, 0.9, [him1rows, him2rows, hresrows]) rplt = biggles.FramedPlot() rplt.add(him1rows, him2rows, hresrows, key) rplt.xlabel = 'Center Rows' cplt = biggles.FramedPlot() cplt.add(him1cols, him2cols, hrescols) cplt.xlabel = 'Center Columns' rplt.aspect_ratio = 1 cplt.aspect_ratio = 1 ctab = biggles.Table(1, 2) ctab[0, 0] = rplt ctab[0, 1] = cplt tab[0, 0] = residplt tab[1, 0] = ctab images._writefile_maybe(tab, **keys) images._show_maybe(tab, **keys) return tab
y.append(gwhich[n][0]) yerr1.append(gwhich[n][1]) yerr2.append(sqrt(gwhich[n][1]**2 + gwhich[n][2]**2)) return x, y, yerr1, yerr2 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"))
if yerri == 0.: sigmas.append(1000.) else: sigmas.append(float(yi - ymedian) / float(yerri)) r = hist.prehist(sigmas) sigshist = hist.h1(30, -6, 6).fill(sigmas) sigsplot = sigshist.plot(False) sigsplot.add(sigshist.stepsfill(-6, -2, True)) sigsplot.add(sigshist.stepsfill(2, 6, True)) sigsplot.add(sigshist.steps(True)) sigsplot.x1.label = "Sigmas away from median efficiency" sigsplot.add( biggles.PlotLabel( 1. / 6., 1. / 5., str(int(round(sigshist.sum(-6, -2) + sigshist.underflow))) + r" runs with low $\epsilon$", angle=90, halign="left")) sigsplot.add( biggles.PlotLabel(5. / 6., 1. / 5., str(int(round(sigshist.sum(2, 6) + sigshist.overflow))) + r" runs with high $\epsilon$", angle=90, halign="left")) sigsplot.add( biggles.PlotLabel(0.5, 1. / 5., str( int(
#!/usr/bin/env python import biggles import math import numpy x = numpy.arange(0, 3 * math.pi, math.pi / 10) y = numpy.sin(x) p = biggles.FramedPlot() p.title = "Title" p.xlabel = "X axis" p.ylabel = "Y axis" p.add(biggles.Histogram(y)) p.add(biggles.PlotLabel(.5, .5, "Histogram", color=0xcc0000)) t1 = biggles.Table(1, 2) t1[0, 0] = p t1[0, 1] = p t2 = biggles.Table(2, 1) t2[0, 0] = t1 t2[1, 0] = p t2.write("example3.png", dpi=55) t2.write("example3.eps") t2.write("example3.pdf") t2.show()
plots = 4 ## add aditional plot as specified in options additional = options.get('additional_profile', None) if additional: aRec, aLig = toIntList(additional) plots = 5 b = biggles.FramedArray(plots, 1) b.title = cName b.xlabel = 'solution' b.ylabel = 'fraction of native contacts' ## xray b[0, 0].add(biggles.Curve(range(512), data[0][0])) b[0, 0].add(biggles.PlotLabel(.5, .95, 'Xray', size=4)) ## best solutions r, l = best_soln[0], best_soln[1] b[1, 0].add(biggles.Curve(range(512), data[r - 1][l - 1])) label = 'the highest number of good scoring solutions (%i/%i)' % (r, l) b[1, 0].add(biggles.PlotLabel(.5, .95, label, size=4)) ## best rank r, l = best_rank[0], best_rank[1] b[2, 0].add(biggles.Curve(range(512), data[r - 1][l - 1])) label = 'the largest number of high rankng solutions (%i/%i)' % (r, l) b[2, 0].add(biggles.PlotLabel(.5, .95, label, size=4)) ## best overall r, l = best[0], best[1]
0].add(biggles.Points(rnum, eff, symboltype="filled circle", symbolsize=0.2)) p1[0, 0].add(biggles.SymmetricErrorBarsY(rnum, eff, efferr)) p1[0, 0].add(biggles.LineY(1., linetype="dotted")) p1[0, 0].yrange = (0.987, 1.005) p1[0, 0].xrange = (min(rnum) - 100, max(rnum) + 100) p1[1, 0].add(biggles.Points(rnum, eff, symboltype="filled circle", symbolsize=0.2)) p1[1, 0].add(biggles.SymmetricErrorBarsY(rnum, eff, efferr)) p1[1, 0].add(biggles.LineY(1., linetype="dotted")) p1[1, 0].yrange = (0.8, 1.1) p1[1, 0].xrange = (min(rnum) - 100, max(rnum) + 100) p1.xlabel = "Run number" p1.ylabel = "BarrelBhabha trigger efficiency" p1[1, 0].add(biggles.PlotLabel(0.25, 0.25, "same outliers as last time")) p1.show() p1.write_eps("plottrig3_p1.eps") print map(lambda (r, e): r, filter(lambda (r, e): e < 0.99, zip(rnum, eff))) print filter(lambda (r, err): err == 0., zip(rnum, efferr)) p1 = biggles.FramedPlot() p1.add(biggles.Points(rnum, eff, symboltype="filled circle", symbolsize=0.7)) p1.add(biggles.SymmetricErrorBarsY(rnum, eff, efferr)) p1.add(biggles.LineY(1., linetype="dotted")) p1.yrange = (0.987, 1.005) p1.xrange = (min(rnum) - 100, max(rnum) + 100) p1.x1.label = "Run number" p1.y1.label = "BarrelBhabha trigger efficiency" p1.add( biggles.PlotLabel(0.5, 0.15,