Debian Codegraph @

texmf-dist/tex/generic/pictex/errorbars.tex

raw
1 %
2 % TeX macros to plot error bars with the PicTeX macros.
3 %
4 % These macros are largely derived from the examples in the back
5 % of the PiCTeX manual.
6 %
7 % To plot with a mark at each data point, simply say
8 %
9 % \plotWith mark M at x1 y1 x2 y2 .... xN yN /
10 %
11 % where "M" is a mark character {e.g. $\bullet$}
12 %
13 % To include error bars in the plot, say:
14 %
15 % \plotWithErrorBars mark M at
16 % x1 y1 e1
17 % x2 y2 e2 .... xN yN eN
18 % /
19 %
20 % The line-breaking isn't needed. Marks are placed on the graph
21 % at (xi, yi) for each data point. Vertical error bars are drawn
22 % from (xi, yi + ei) to (xi, yi - ei).
23 %
24 % The cross-bar at the top and bottom of the error bars is normally
25 % 5 pts, but can be changed by setting the \crossbarlength dimen.
26 %
27 %
28 % Dirk Grunwald Apr 20 1988
29 %
30 %
31 \newdimen\dyposition
32 \newdimen\crossbarlength
33 \crossbarlength=5pt
34 \newdimen\lastPlotX
35 \newdimen\lastPlotY
36 \newdimen\tmpPlotX
37 \newdimen\tmpPlotY
38 %
39 %
40 \def\plotErrorBar#1 #2 #3 #4{%
41 \message{ Plot #4 at #1 #2 }%
42 \put {#4} at {#1} {#2}
43 \dyposition=\Ydistance{#3}
44 \put{%
45 \vbox{%
46 \hsize=\crossbarlength%
47 \hrule height \linethickness%
48 \vskip -.5\linethickness%
49 \centerline{\vrule width \linethickness height 2\dyposition}%
50 \nointerlineskip%
51 \vskip -.5\linethickness%
52 \hrule height \linethickness}%
53 } at {#1} {#2} }
54 %
55 \def\plotWithErrorBars mark #1 at #2 #3 #4 {%
56 \def\errorBarMark{#1}%
57 %
58 % plot first point
59 %
60 \plotErrorBar {#2} {#3} {#4} {\errorBarMark}
61 \lastPlotX=\Xdistance{#2}%
62 \lastPlotY=\Ydistance{#3}%
63 \futurelet\nextcharacter\plotErrorBarLoop}
64 %
65 \def\plotErrorBarLoop{%
66 \if/\nextcharacter%
67 \def\plotErrorBarAction{\plotErrorBarFinish}%
68 \else%
69 \def\plotErrorBarAction{\plotErrorBarContinued}%
70 \fi%
71 \plotErrorBarAction}
72 %
73 \def\plotErrorBarFinish/ {}
74 %
75 \def\plotErrorBarContinued#1 #2 #3 {%
76 \plotErrorBar {#1} {#2} {#3} {\errorBarMark}%
77 \tmpPlotX = \Xdistance{#1}%
78 \tmpPlotY = \Ydistance{#2}%
79 \setdimensionmode%
80 \plot {\lastPlotX} {\lastPlotY} {\tmpPlotX} {\tmpPlotY} /
81 \setcoordinatemode%
82 \lastPlotX = \tmpPlotX%
83 \lastPlotY = \tmpPlotY%
84 \futurelet\nextcharacter\plotErrorBarLoop}
85 %
86 \def\plotWith mark #1 at #2 #3 {%
87 \def\plotWithMark{#1}%
88 %
89 % plot first point
90 %
91 \message{Plot {\plotWithMark} at #2 #3}%
92 \put {\plotWithMark} at {#2} {#3}
93 \lastPlotX=\Xdistance{#2}%
94 \lastPlotY=\Ydistance{#3}%
95 \futurelet\nextcharacter\plotWithLoop}
96 %
97 \def\plotWithLoop{%
98 \if/\nextcharacter%
99 \def\plotWithAction{\plotWithFinish}%
100 \else%
101 \def\plotWithAction{\plotWithContinued}%
102 \fi%
103 \plotWithAction}
104 %
105 \def\plotWithFinish/ {}
106 %
107 \def\plotWithContinued#1 #2 {%
108 \message{ Plot {\plotWithMark} at #1 #2}%
109 \put {\plotWithMark} at {#1} {#2}
110 \tmpPlotX = \Xdistance{#1}%
111 \tmpPlotY = \Ydistance{#2}%
112 \setdimensionmode%
113 \plot {\lastPlotX} {\lastPlotY} {\tmpPlotX} {\tmpPlotY} /
114 \setcoordinatemode%
115 \lastPlotX = \tmpPlotX%
116 \lastPlotY = \tmpPlotY%
117 \futurelet\nextcharacter\plotWithLoop}