summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/misc/plotting.tex
blob: ab3c59d0ac0837e003d484213dc0a47efca2cf1f (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
%
%	plotting.tex - TeX Plotting Macros
%
%	author: Laurence G. Yaffe (lgy@newton.phys.washington.edu)	1987
%
\setbox0 = \hbox{$0$}%
\newdimen \digitheight		\digitheight  = \ht0
\newdimen \titlespacing		\titlespacing = 1.5 ex
\newdimen \labelspacing		\labelspacing = 0.9 ex
\newdimen \labelwidth		\labelwidth   = 0.0 pt
\newdimen \ticklength		\ticklength   = 0.7 em
\newdimen \plotheight		\plotheight   = 5.0 in
\newdimen \plotwidth		\plotwidth    = 5.0 in
\newdimen \linewidth		\linewidth    = 0.241 pt
\newskip  \padding		\padding      = 0pt plus 1fil
%
\newbox	\xAxis
\newbox	\XAxis
\newbox	\yAxis
\newbox	\YAxis
\newbox	\PlotData
\newbox	\PlotBox
%
\def\ratio	#1:#2%		adjust padding for log scale plotting
    {%
    \count255 = #1#2
    \ifnum \count255=11	\global\padding = 0pt plus 1.00000 fil \else
    \ifnum \count255=12	\global\padding = 0pt plus 0.30103 fil \else
    \ifnum \count255=23	\global\padding = 0pt plus 0.17609 fil \else
    \ifnum \count255=34	\global\padding = 0pt plus 0.12494 fil \else
    \ifnum \count255=45	\global\padding = 0pt plus 0.09691 fil \else
    \ifnum \count255=56	\global\padding = 0pt plus 0.07918 fil \else
    \ifnum \count255=67	\global\padding = 0pt plus 0.06695 fil \else
    \ifnum \count255=78	\global\padding = 0pt plus 0.05799 fil \else
    \ifnum \count255=89	\global\padding = 0pt plus 0.05115 fil \else
    \ifnum \count255=91	\global\padding = 0pt plus 0.04576 fil \else
    \ifnum \count255=13	\global\padding = 0pt plus 0.47712 fil \else
    \ifnum \count255=14	\global\padding = 0pt plus 0.60206 fil \else
    \ifnum \count255=24	\global\padding = 0pt plus 0.30103 fil \else
    \ifnum \count255=25	\global\padding = 0pt plus 0.39794 fil \else
    \ifnum \count255=26	\global\padding = 0pt plus 0.47712 fil \else
    \ifnum \count255=36	\global\padding = 0pt plus 0.30103 fil \else
    \ifnum \count255=46	\global\padding = 0pt plus 0.17609 fil \else
    \ifnum \count255=61	\global\padding = 0pt plus 0.22185 fil \else
    \ifnum \count255=51	\global\padding = 0pt plus 0.30103 fil \else
    \ifnum \count255=41	\global\padding = 0pt plus 0.39794 fil \else
    \ifnum \count255=31	\global\padding = 0pt plus 0.52288 fil \else
    \ifnum \count255=21	\global\padding = 0pt plus 0.69897 fil \else
			\global\padding = 0pt
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    }%
%
\def\centered	#1{\vbox to 0pt {\vss \hbox to 0pt {\hss #1\hss}\vss}}%
%
\def\dash	#1%
    {%
    \vbox {\hrule height 0.5 \linewidth depth 0.5 \linewidth width #1}%
    }%
%
\def\yaxis	#1#2%
    {%
    \global\setbox \yAxis = \hbox
	{%
	\def \temp {#1}%
	\ifx \temp\empty \else
	    \vbox to \plotheight {\vss \hbox {#1}\vss}%
	    \kern 0.7 \titlespacing
	\fi
	\def \temp {#2}%
	\ifx \temp\empty \else
	    \labelwidth = 0pt
	    \setbox1=\box0\ytic #2,\cr,%
	    \ifnum \labelwidth = 0 \kern -\labelspacing \fi
	    \hbox to \labelwidth {\hfil}\box0%
	\fi
	\hbox to 0pt
	    {\hss \vrule height \plotheight depth 0pt width \linewidth \hss}%
	}%
    }%
\def\ytic	#1,%
    {%
    \def \temp {#1}%
    \def \quit {\cr}%
    \ifx \temp\quit
	\let\next=\relax
	\setbox0 = \vbox to \plotheight {\unvbox0 \unskip}%
    \else
	\let\next=\ytic \skip0 = \padding
	\setbox1 = \hbox {\tenpoint $#1$}%
	\ifnum \labelwidth < \wd1
	       \labelwidth = \wd1
	\fi
	\setbox1 = \hbox
	    {%
	    \smash
		{%
		\ifnum \wd1 = 0
		    \kern \labelspacing
		    \hbox to 0pt {\dash {0.67 \ticklength}\hss}%
		\else
		    \lower 0.42 \digitheight \hbox to 0pt {\hss \unhbox1}%
		    \kern \labelspacing
		    \hbox to 0pt {\dash \ticklength \hss}%
		\fi
		}%
	    }%
	\setbox0 = \vbox to \plotheight {\box1 \vskip \skip0 \unvbox0}%
    \fi
    \next
    }%
%
\def\Yaxis	#1#2%
    {%
    \global\setbox \YAxis = \hbox
	{%
	\hbox to 0pt
	    {\hss \vrule height \plotheight depth 0pt width \linewidth \hss}%
	\def \temp {#2}%
	\ifx \temp\empty \else \setbox1=\box0 \Ytic #2,\cr,\box0 \fi
	\def \temp {#1}%
	\ifx \temp\empty \else
	    \kern 0.7 \titlespacing
	    \vbox to \plotheight {\vss \hbox {#1}\vss}%
	\fi
	}%
    }%
\def\Ytic	#1,%
    {%
    \def \temp {#1}%
    \def \quit {\cr}%
    \ifx \temp\quit
	\let\next=\relax
	\setbox0 = \vbox to \plotheight {\unvbox0 \unskip}%
    \else
	\let\next=\Ytic \skip0=\padding
	\setbox1 = \hbox {\tenpoint $#1$}%
	\setbox1 = \hbox
	    {%
	    \smash
		{%
		\ifnum \wd1=0
		    \hbox to 0pt {\hss \dash {0.67 \ticklength}}%
		\else
		    \hbox to 0pt {\hss \dash \ticklength}%
		    \kern \labelspacing
		    \lower 0.42 \digitheight \box1%
		\fi
		}%
	    }%
	\setbox0 = \vbox to \plotheight {\box1 \vskip \skip0 \unvbox0}%
    \fi
    \next
    }%
%
\def\xaxis	#1#2%
    {%
    \global\setbox \xAxis = \vtop
	{%
	\smash {\dash \plotwidth}%
	\nointerlineskip
	\def \temp {#2}%
	\ifx \temp\empty \else \hbox to \plotwidth {\xtic #2,\cr,}\fi
	\nointerlineskip
	\def \temp {#1}%
	\ifx \temp\empty \else
	    \kern 0.7 \titlespacing
	    \hbox to \plotwidth {\hss #1\hss}%
	\fi
	}%
    }%
\def\xtic	#1,%
    {%
    \def \temp {#1}%
    \def \quit {\cr}%
    \ifx \temp\quit
	\let\next=\unskip
    \else
	\let\next=\xtic
	\vtop
	    {%
	    \setbox1 = \hbox to 0pt {\hss \tenpoint $#1$\hss}%
	    \ifnum \ht1=0
		\smash
		  {\hbox to 0pt
		    {\hss \vrule height 0.67 \ticklength width \linewidth \hss}%
		  }%
	    \else
		\smash
		  {\hbox to 0pt
		    {\hss \vrule height \ticklength width \linewidth \hss}%
		  }%
		\nointerlineskip
		\kern \labelspacing
		\box1%
	    \fi
	    }%
	\hskip \padding
    \fi
    \next
    }%
%
\def\Xaxis	#1#2%
    {%
    \global\setbox \XAxis = \vbox
	{%
	\def \temp {#1}%
	\ifx \temp\empty \else
	    \hbox to \plotwidth {\hss #1\hss}%
	    \kern \titlespacing
	\fi
	\nointerlineskip
	\def \temp {#2}%
	\ifx \temp\empty \else \hbox to \plotwidth {\Xtic #2,\cr,}\fi
	\nointerlineskip
	\smash {\dash \plotwidth}%
	}%
    }%
\def\Xtic	#1,%
    {%
    \def \temp {#1}%
    \def \quit {\cr}%
    \ifx \temp\quit
	\let\next=\unskip
    \else
	\let\next=\Xtic
	\vbox
	    {%
	    \setbox1 = \hbox to 0pt {\hss \tenpoint $#1$\hss}%
	    \ifnum \ht1=0
		\smash
		  {\hbox to 0pt
		    {\hss \vrule depth 0.67 \ticklength width \linewidth \hss}%
		  }%
	    \else
		\box1%
		\kern \labelspacing
		\nointerlineskip
		\smash
		  {\hbox to 0pt
		    {\hss \vrule depth \ticklength width \linewidth \hss}%
		  }%
	    \fi
	    }%
	\hskip \padding
    \fi
    \next
    }%
%
\def\plotbox	(#1,#2)%
    {%
    \global\setbox \PlotData = \hbox to 0pt
	{%
	\unhbox \PlotData
	\rlap {\kern #1\plotwidth \raise #2\plotheight \copy\PlotBox}%
	}%
    }%
\def\plottext	(#1,#2)#3%
    {%
    \setbox \PlotBox = \hbox {#3}%
    \plotbox (#1,#2)%
    }%
\def\plotpoint	(#1,#2)%
    {%
    \setbox \PlotBox = \centered.%
    \plotbox (#1,#2)%
    }%
\def\plotsymbol	(#1,#2)#3%
    {%
    \setbox \PlotBox = \centered {#3}%
    \plotbox (#1,#2)%
    }%
\def\xrange	#1]{\def\XRange {#1]}}%
\def\yrange	#1]{\def\YRange {#1]}}%
%
\def\makeplot	#1#2#3%
    {%
    \plotwidth = #1 \plotheight = #2
    \setbox \xAxis = \hbox to \plotwidth  {\hfil}%
    \setbox \XAxis = \hbox to \plotwidth  {\hfil}%
    \setbox \yAxis = \vbox to \plotheight {\vfil}%
    \setbox \YAxis = \vbox to \plotheight {\vfil}%
    \setbox \PlotData = \hbox {}%
    {#3}%
    \hbox
	{%
	\box \yAxis
	\box \PlotData
	\vbox
	    {%
	    \box \XAxis
	    \nointerlineskip \kern \plotheight \nointerlineskip
	    \box \xAxis
	    }%
	\box \YAxis
	}%
    }%
%
\def\psfile	#1%		--- deferred input of postscript file ---
    {%
    \global\setbox \PlotData = \hbox to 0pt
	{%
	\unhbox \PlotData \special {psfile=#1}%
	}%
    }%
%
\def\addPS	#1%		--- immediate input of postscript commands ---
    {%
    \global\setbox \PlotData = \hbox to 0pt
	{%
	\unhbox \PlotData \special {"#1}%
	}%
    }%
%
\def\plotdatafile	#1#2%		--- deferred input of data file ---
    {%
    \global\setbox \PlotData = \hbox to 0pt
	{%
	\unhbox \PlotData
	\special
	    {%
	    datafile="#1"
	    dash="[#2]"
	    xrange="\XRange"
	    yrange="\YRange"
	    hsize=\the\plotwidth\space
	    vsize=\the\plotheight\space
	    linewidth=\the\linewidth
	    }%
	}%
    }%
%
\def\plotdata	#1#2%			--- immediate input of data points ---
    {%
    \global\setbox \PlotData = \hbox to 0pt
	{%
	\unhbox \PlotData
	\special
	    {%
	    datalist="#1"
	    dash="[#2]"
	    xrange="\XRange"
	    yrange="\YRange"
	    hsize=\the\plotwidth\space
	    vsize=\the\plotheight\space
	    linewidth=\the\linewidth
	    }%
	}%
    }%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%	Trivial Plotting Example
%
%\makeplot {5 in}{4.5 in}%
%    {%
%    \linewidth = 0.3 pt
%    \Xaxis {Title}{}
%    \Yaxis {\kern -5pt $Y$}{,2,4,6,8,10}
%    \yaxis {$y$}{0.0,,0.2,,0.4,,0.6,,0.8,,1.0}
%    \xaxis {$x$}{10^0 \ratio 1:2,\ratio 2:3,\ratio 3:4,\ratio 4:5,\ratio 5:6,
%		      \ratio 6:7,\ratio 7:8,\ratio 8:9,\ratio 9:1,
%		 10^1 \ratio 1:2,\ratio 2:3,\ratio 3:4,\ratio 4:5,\ratio 5:6,
%		      \ratio 6:7,\ratio 7:8,\ratio 8:9,\ratio 9:1,
%		 10^2 \ratio 1:1}
%    \plotsymbol (.9,.9)a
%    \plottext  (.2,.4){some text}
%    \plottext (.25,.7){more text}
%    }%
%\bye