#!/usr/bin/env python #v1.01 4 October 2008 import sys, re import vplot import simpleSVG from math import sqrt title="neural network forecast" outfile='brier.svg' infilename='brier.dat' b=simpleSVG.svg_class(fname=outfile) b.scale() b.group(fill="black") #otherwise fonts are hollow inf=open(infilename,'r') b.xaxis() b.yaxis() yl=[] nl=[] ol=[] while 1: aline=inf.readline() if not aline: break if re.match('\#',aline): a=aline.split() for x in a: exec(x) continue [i,y,n,o]=aline.split() yl.append(float(y)) nl.append(float(n)) ol.append(float(o)) todraw=[] for i in range(0,len(yl)): todraw.append(yl[i]) todraw.append(ol[i]) b.line(0., ob, 1., ob) b.line(ob, 0., ob, 1.) b.line(0., ob/2., 1., .5+ob/2.) b.line(0., 0., 1., 1.) b.draw(todraw,stroke_dasharray="2 3",fill='none') b.group(stroke='red') for i in range(0,len(yl)): y=yl[i] o=ol[i] rad=int(round(sqrt(nl[i]))) # area of circle will be proportional to n s=ob/2.+y/2. if (y=ob and o>s): b.circle(y,o,rad,fill='red') else: b.circle(y,o,rad,fill='none') b.group() b.text(.5,1.02,0.,title,font_size="24pt",text_anchor="middle") b.text(-.07,.3,90.,'observed relative frequency',font_size="14pt") b.text(.3,-.08,0.,'forecast probability',font_size="14pt") b.close()