summaryrefslogtreecommitdiff
path: root/graphics/epix/samples/histogram.xp
blob: 47e704fba2e945b4feea82308beabfe5744fa912 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

// See binom.cc for instructions on creating data file binom.dat

double erf(double x)
{
  return 100*exp(-0.02*(x-50)*(x-50))/sqrt(50*M_PI);
}

int main() 
{
  picture(P(0,0),P(100,20), "6 x 6in");

  begin();

  grid(1,10);

  // read disk file
  data_file binom("binom.dat");

  // create "bins" for bar chart
  data_bins db05(-0.5, 100.5, 101);  // 5% biased coin
  data_bins db10(-0.5, 100.5, 101);  // 10%
  data_bins db30(-0.5, 100.5, 101);  // 30%
  data_bins db50(-0.5, 100.5, 101);  // 50%

  db05.read(binom.column(1));
  db10.read(binom.column(2));
  db30.read(binom.column(3));
  db50.read(binom.column(4));

  legend L;

  fill();
  gray(0.6);
  db05.bar_chart(100);
  L.fill_item("5\\%");

  gray(0.4);
  db10.bar_chart(100);
  L.fill_item("10\\%");

  gray(0.2);
  db30.bar_chart(100);
  L.fill_item("30\\%");

  gray(0);
  db50.bar_chart(100);
  L.fill_item("50\\%");

  nofill();

  font_size("footnotesize");
  tick_size(1);
  bottom_axis(10, P(0,-4), b).draw();

  left_axis(10, P(-4,0), l).subdivide(2).draw();

  bold(Red());
  plot(erf, xmin(), xmax(), 240);
  L.path_item("Normal");

  font_size("LARGE");
  L.key_size(18);
  L.draw(P(50, 12.5), P(2,2), tr);

  font_face("sc");
  label(P(0.5*(xmin()+xmax()), ymax()), P(0,12), 
	"Tossing a Biased Coin, 100,000 Trials", t);

  font_size(); // reset to default
  label(P(0.5*(xmin()+xmax()), ymin()), P(0,-18), 
	"Number of Heads (100 Tosses per Trial)", b);

  degrees();
  label_angle(90);
  label(P(xmin(), 0.5*(ymin()+ymax())), P(-18,0), "Percentage of Trials", l);

  pst_format();
  end();
}