File: shadeplot.xp

package info (click to toggle)
epix 1.2.22-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,256 kB
  • sloc: cpp: 16,847; sh: 5,054; makefile: 159; lisp: 6
file content (61 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (9)
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
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;
double k(4);         // change width of hump
double dx(0.05);     // width of thin shaded region
double x(1/sqrt(k)); // position of thin shaded region

const double dy(0.5);

double f(double t)
{
  return sqrt(fabs(k)/(2*M_PI))*exp(-k*t*t);
}

P pt1(x, f(x)+2*dy);
P pt2(x+dx,f(x)+dy);
P pt3(x+3*dx,f(x));

Color shade1(Black(0.1));
Color shade2(Black(0.4));
Color shade3(Black(0.6));

int main()
{
  picture(P(0,0), P(1,1), "150x150pt");

  begin();
  legend L;
  L.backing(Neutral());

  fill(shade1); 
  shadeplot(f, xmin(), x, 90);
  L.fill_item("$=\\displaystyle\\int_a^x f(t)\\,dt$");

  fill(shade2);
  rect(P(x,0), P(x+dx, f(x)));
  L.fill_item("= $f(x)\\,dx\\vphantom{\\Bigg|}$");

  fill(shade3);
  shadeplot(f, x, x+dx, 10);
  L.fill_item("= $F(x+dx)-F(x)$");

  bold();
  plot(f, xmin(), xmax(), 120);

  plain();
  h_axis(4);
  v_axis(4);

  font_size("scriptsize");
  L.draw(canvas().tr(), P(-2,-2), bl);

  font_size("footnotesize");
  label(P(xmin(),0), P(0,-5), "$a$", b);
  label(P(x,0), P(0,-5), "$x$", b);
  label(P(x+dx,0), P(0,-2), "$x+dx$", br);

  pst_format();

  end();
}