\cat programming
legend_ex.mp
input TEX; input graph; input legend; input math; beginfig(1); draw begingraph(4in, 2in); picture key[], dash[]; key0 := btex $\sin(x)$ etex; key1 := btex $\cos(x)$ etex; dash0 := nullpicture; dash1 := evenly; gdraw fpath(sin)(0, 0.1, 2*pi) dashed dash0; gdraw fpath(cos)(0, 0.1, 2*pi) dashed dash1; setrange(0, -1, 2*pi, 1); color gridcolor; gridcolor := 0.70*white; autogrid(, grid.lft) withcolor gridcolor; grid.bot("0", 0) withcolor gridcolor; grid.bot(btex $\pi$ etex, pi) withcolor gridcolor; for x=0.5, 1.5, 2: grid.bot(TEX(decimal(x) & "$\pi$"), x*pi) withcolor gridcolor; endfor; glabel.bot(btex $x$ etex, OUT); glabel.lft(btex $f(x)$ etex, OUT); glabel.rt(legend(1cm)(key, dash), OUT); endgraph; endfig; end;
histogram_ex.txt
1084072.500000 2 1115945.000000 1 1147817.500000 6 1179690.000000 11 1211562.500000 23 1243435.000000 39 1275307.500000 64 1307180.000000 82 1339052.500000 96 1370925.000000 104 1402797.500000 108 1434670.000000 86 1466542.500000 106 1498415.000000 87 1530287.500000 73 1562160.000000 43 1594032.500000 25 1625905.000000 23 1657777.500000 11 1689650.000000 7 1721522.500000 13
histogram_ex
input graph; input sarith; input histogram; beginfig(1); draw histogram(btex Distribution of $N$ etex)("histogram_ex.txt") (4in, 2in) (btex $N (10^6 mg/L)$ etex, btex Frequency etex rotated 90) ("1e6", "1") (1.1, 0.1, 1.8)(0, 20, 100) (blue, 0.70*white); endfig; end;