1/* -*-ePiX-*- */ 2#include "epix.h" 3using namespace ePiX; 4 5// See binom.cc for instructions on creating data file binom.dat 6 7double erf(double x) 8{ 9 return 100*exp(-0.02*(x-50)*(x-50))/sqrt(50*M_PI); 10} 11 12int main() 13{ 14 picture(P(0,0),P(100,20), "6 x 6in"); 15 16 begin(); 17 18 grid(1,10); 19 20 // read disk file 21 data_file binom("binom.dat"); 22 23 // create "bins" for bar chart 24 data_bins db05(-0.5, 100.5, 101); // 5% biased coin 25 data_bins db10(-0.5, 100.5, 101); // 10% 26 data_bins db30(-0.5, 100.5, 101); // 30% 27 data_bins db50(-0.5, 100.5, 101); // 50% 28 29 db05.read(binom.column(1)); 30 db10.read(binom.column(2)); 31 db30.read(binom.column(3)); 32 db50.read(binom.column(4)); 33 34 legend L; 35 36 fill(); 37 gray(0.6); 38 db05.bar_chart(100); 39 L.fill_item("5\\%"); 40 41 gray(0.4); 42 db10.bar_chart(100); 43 L.fill_item("10\\%"); 44 45 gray(0.2); 46 db30.bar_chart(100); 47 L.fill_item("30\\%"); 48 49 gray(0); 50 db50.bar_chart(100); 51 L.fill_item("50\\%"); 52 53 nofill(); 54 55 font_size("footnotesize"); 56 tick_size(1); 57 bottom_axis(10, P(0,-4), b).draw(); 58 59 left_axis(10, P(-4,0), l).subdivide(2).draw(); 60 61 bold(Red()); 62 plot(erf, xmin(), xmax(), 240); 63 L.path_item("Normal"); 64 65 font_size("LARGE"); 66 L.key_size(18); 67 L.draw(P(50, 12.5), P(2,2), tr); 68 69 font_face("sc"); 70 label(P(0.5*(xmin()+xmax()), ymax()), P(0,12), 71 "Tossing a Biased Coin, 100,000 Trials", t); 72 73 font_size(); // reset to default 74 label(P(0.5*(xmin()+xmax()), ymin()), P(0,-18), 75 "Number of Heads (100 Tosses per Trial)", b); 76 77 degrees(); 78 label_angle(90); 79 label(P(xmin(), 0.5*(ymin()+ymax())), P(-18,0), "Percentage of Trials", l); 80 81 pst_format(); 82 end(); 83} 84