Debian Codegraph @

texmf-dist/tex/latex/numericplots/NumericPlots.sty

raw
1 % Copyright 2013 Thomas Koenig, Alexander Michel, Michael Baumgart
2 %
3 % This file is part of NumericPlots.
4 %
5 % NumericPlots is free software: you can redistribute it and/or modify
6 % it under the terms of the GNU General Public License as published by
7 % the Free Software Foundation, either version 3 of the License, or
8 % any later version.
9 %
10 % NumericPlots is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 % GNU General Public License for more details.
14 %
15 % You should have received a copy of the GNU General Public License
16 % along with NumericPlots. If not, see <http://www.gnu.org/licenses/>.
17
18 \NeedsTeXFormat{LaTeX2e}
19
20 \ProvidesPackage{NumericPlots}%
21 [2013/09/19 v. 2.0.2 LaTeX package to plot numeric data]
22
23
24 \RequirePackage{calc}
25 \RequirePackage[nomessages]{fp}
26
27 \RequirePackage{ifthen}
28 \RequirePackage{pstricks}
29 \RequirePackage{pst-node}
30 \RequirePackage{pst-plot}
31 \RequirePackage{pstricks-add} % has to be the last of the pst-packages to be loaded!
32 % the following seems not to work. xcolor must be included with x11names option!
33 \RequirePackage{xcolor}
34
35
36 % \makeatletter
37 % \newcommand*{\getlengthwounit}[1]{\strip@pt#1}
38 % \makeatother
39
40
41
42 % =======================================
43 % === Definition of keys and commands ===
44 % =======================================
45 %
46 % All the provided options (keys) are defined in the following section. Maybe it
47 % is possible to store the values of the keys somehow. We then wouldn't have to
48 % define all the new commands..
49
50 \RequirePackage{xkeyval}
51 \RequirePackage{xkvview} % keep track of all keys that are defined
52
53 \newcommand{\testframe}[1]{#1}
54
55
56 % globally needed values as newcommands
57 \newcommand{\NumDataPlotxRange}{1}
58 \newcommand{\NumDataPlotxCoordRange}{1}
59 \newcommand{\NumDataPlotxDataCoordRatio}{1}
60 \newcommand{\NumDataPlotyRange}{1}
61 \newcommand{\NumDataPlotyCoordRange}{1}
62 \newcommand{\NumDataPlotyDataCoordRatio}{1}
63 \newcommand{\NumDataPlotLnTen}{2.3025850929940}
64 \newcommand{\NumDataPlotTickPos}{0}
65
66 \newcommand{\xScaling}{}
67 \newcommand{\yScaling}{}
68
69 \newcommand{\NDPputXcoord}{0}
70 \newcommand{\NDPputYcoord}{0}
71 \newcommand{\NDPRefPoint}{c}
72 \newcommand{\NDPputRotation}{0}
73
74 \newcommand{\NumDataPlotBuffer}{0}
75 \newcommand{\NumDataPlotBufferI}{0}
76 \newcommand{\TicksXRight}{0}
77 \newcommand{\TicksXLeft}{0}
78 \newcommand{\TicksYRight}{0}
79 \newcommand{\TicksYLeft}{0}
80 \newcommand{\TickLabelsXRight}{0}
81 \newcommand{\TickLabelsXLeft}{0}
82 \newcommand{\TickLabelsYRight}{0}
83 \newcommand{\TickLabelsYLeft}{0}
84 \newcommand{\xTickLength}{-10}
85 \newcommand{\yTickLength}{-10}
86
87 \newcommand{\xNrTicks}{1}
88 \newcommand{\yNrTicks}{1}
89 \newcommand{\xNrTickLabels}{1}
90 \newcommand{\yNrTickLabels}{1}
91
92 \newboolean{PlotLeftAxis}
93 \setboolean{PlotLeftAxis}{true}
94 \newboolean{PlotRightAxis}
95 \setboolean{PlotRightAxis}{true}
96
97 \newboolean{PlotLowerAxis}
98 \setboolean{PlotLowerAxis}{true}
99 \newboolean{PlotUpperAxis}
100 \setboolean{PlotUpperAxis}{true}
101
102 \newcommand{\nrLegendCols}{1}
103 \newlength{\LegLineWidth}\setlength{\LegLineWidth}{20pt}
104
105 \newboolean{LegendOrientationLeft}
106 \newboolean{LegendOrientationRight}
107 \newboolean{LegendOrientationCenter}
108 \setboolean{LegendOrientationLeft}{true}
109 \setboolean{LegendOrientationRight}{false}
110 \setboolean{LegendOrientationCenter}{false}
111
112
113 \newcommand{\LogxAxis}{}
114 \newcommand{\LogxAxisLabel}[1]{$#1$}
115 \newcommand{\LogyAxis}{}
116 \newcommand{\LogyAxisLabel}[1]{$#1$}
117
118
119 \newcounter{BufferCounter}
120 % ----------------------------------------------------------------------------
121 % | define keys for the axis style etc.
122 % ----------------------------------------------------------------------------
123
124 % define some command keys
125 % the command keys only save the provided value in \NumDataPlot<key> for later
126 % use. The standard values for the command keys are set at the end of the
127 % package.
128
129 \define@cmdkeys[NumericDataPlot]{Axis}[NumDataPlot]
130 {xMax, xMin,
131 Dx,
132 dx, % so far, these are always calculated and cannot be set by user
133 xCoordMax, xCoordMin,
134 yMax, yMin,
135 Dy,
136 dy, % so far, these are always calculated and cannot be set by user
137 yCoordMax, yCoordMin
138 }
139
140
141 \define@boolkey[NumericDataPlot]{Axis}{xLog}[true]{
142 \ifNumericDataPlot@Axis@xLog
143 \renewcommand{\LogxAxis}{log}
144 \renewcommand{\LogxAxisLabel}[1]{
145 \ifthenelse{##1<1}{
146 \ifthenelse{##1>-1}{%
147 $10^{0}$%
148 }{%
149 $10^{##1}$%
150 }}%
151 {%
152 $10^{##1}$%
153 }%
154 }%
155 \else
156 \renewcommand{\LogxAxis}{}
157 \renewcommand{\LogxAxisLabel}[1]{$##1$}
158 \fi
159 }
160
161 \define@boolkey[NumericDataPlot]{Axis}{yLog}[true]{
162 \ifNumericDataPlot@Axis@yLog
163 \renewcommand{\LogyAxis}{log}
164 \renewcommand{\LogyAxisLabel}[1]{
165 \ifthenelse{##1<1}{
166 \ifthenelse{##1>-1}{%
167 $10^{0}$%
168 }{%
169 $10^{##1}$%
170 }}%
171 {%
172 $10^{##1}$%
173 }%
174 }%
175 \else
176 \renewcommand{\LogyAxis}{}
177 \renewcommand{\LogyAxisLabel}[1]{$##1$}
178 \fi
179 }
180
181 \define@boolkey[NumericDataPlot]{Axis}{xLogNoSubGrid}[true]{
182 }
183 \define@boolkey[NumericDataPlot]{Axis}{yLogNoSubGrid}[true]{
184 }
185
186 \define@boolkey[NumericDataPlot]{Axis}{yNearlyTight}[false]{}
187
188 % xMin and yMin also set xO/yO. It will later be ensured that if the user
189 % provides a value for xO/yO, these values will be used! (in order to do so, it
190 % is always necessary to call the following two commands in the given order:
191 % \setkeys[NumericDataPlot]{Axis}{<list of keys>}
192 % \setrmkeys[NumericDataPlot]{AxisWait}
193 % where <list of keys> can contain all the keys from Axis and from AxisWait)
194 % same goes for DDy and DDx (Dy for labels): By default, the values of dy and dx
195 % will be used.
196 \define@cmdkeys[NumericDataPlot]{AxisWait}[NumDataPlot]{xO, yO, DDy, DDx}{}
197
198 \define@boolkeys[NumericDataPlot]{xAxis}
199 {NoGrid, NoTicks, NoLabel, NoTickLabel}[true]
200
201 \define@boolkeys[NumericDataPlot]{yAxis}
202 {NoGrid, NoTicks, NoLabel, NoTickLabel}[true]
203
204
205
206 \define@choicekey+[NumericDataPlot]{xAxis}{AxisStyle}[\val\nrAxisStyle]
207 {Boxed,Lower,Upper,None}{
208 \ifcase\nrAxisStyle\relax
209 \setboolean{PlotLowerAxis}{true}
210 \setboolean{PlotUpperAxis}{true}
211 \or
212 \setboolean{PlotLowerAxis}{true}
213 \setboolean{PlotUpperAxis}{false}
214 \or
215 \setboolean{PlotLowerAxis}{false}
216 \setboolean{PlotUpperAxis}{true}
217 \or
218 \setboolean{PlotLowerAxis}{false}
219 \setboolean{PlotUpperAxis}{false}
220 \fi
221 }{
222 \PackageWarning{NumericPlots}
223 {AxisStyle #1 not defined. Use Boxed, Lower, Upper or None}
224 }
225
226 \define@choicekey+[NumericDataPlot]{yAxis}{AxisStyle}[\val\nrAxisStyle]
227 {Boxed,Right,Left,None}{
228 \ifcase\nrAxisStyle\relax
229 \setboolean{PlotRightAxis}{true}
230 \setboolean{PlotLeftAxis}{true}
231 \or
232 \setboolean{PlotRightAxis}{true}
233 \setboolean{PlotLeftAxis}{false}
234 \or
235 \setboolean{PlotRightAxis}{false}
236 \setboolean{PlotLeftAxis}{true}
237 \or
238 \setboolean{PlotRightAxis}{false}
239 \setboolean{PlotLeftAxis}{false}
240 \fi
241 }{
242 \PackageWarning{NumericPlots}
243 {AxisStyle #1 not defined. Use Boxed, Right, Left or None}
244 }
245
246
247 % ----------------------------------------------------------------------------
248 % | general keys
249 % |
250 % | picture width etc.
251 % ----------------------------------------------------------------------------
252
253 \define@cmdkeys[NumericDataPlot]{General}[NumDataPlotG]{%
254 xPicMin, yPicMin, xPicMax, yPicMax, TickLength%
255 }
256
257
258 \define@key[NumericDataPlot]{General}{llx}[\StdLLX]{%
259 \psset{llx=-#1}%
260 \addtolength{\OffsetWidth}{-\StdLLX}%
261 \addtolength{\OffsetWidth}{#1}%
262 }
263 \define@key[NumericDataPlot]{General}{urx}[\StdURX]{%
264 \psset{urx=#1}%
265 \addtolength{\OffsetWidth}{-\StdURX}%
266 \addtolength{\OffsetWidth}{#1}%
267 }
268 \define@key[NumericDataPlot]{General}{lly}[\StdLLY]{%
269 \psset{lly=-#1}%
270 \addtolength{\OffsetHeight}{-\StdLLY}%
271 \addtolength{\OffsetHeight}{#1}%
272 }
273 \define@key[NumericDataPlot]{General}{ury}[\StdURY]{%
274 \psset{ury=#1}%
275 \addtolength{\OffsetHeight}{-\StdURY}%
276 \addtolength{\OffsetHeight}{#1}%
277 }
278
279
280
281 % ------------------------------------------------------------------------------
282 % | keys for the put commands
283 % ------------------------------------------------------------------------------
284
285 \define@key[NumericDataPlot]{put}{x}{
286 \FPsub{\NumDataPlotBuffer}{#1}{\NumDataPlotxMin}
287 \FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotxDataCoordRatio}
288 \FPadd{\NDPputXcoord}{\NumDataPlotBuffer}{\NumDataPlotxCoordMin}
289 }
290 \define@key[NumericDataPlot]{put}{y}{
291 \FPsub{\NumDataPlotBuffer}{#1}{\NumDataPlotyMin}
292 \FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotyDataCoordRatio}
293 \FPadd{\NDPputYcoord}{\NumDataPlotBuffer}{\NumDataPlotyCoordMin}
294 }
295 \define@key[NumericDataPlot]{put}{RefPoint}[c]{
296 \renewcommand{\NDPRefPoint}{#1}
297 }
298 \define@key[NumericDataPlot]{put}{Rot}[0]{
299 \renewcommand{\NDPputRotation}{#1}
300 }
301
302 %-------------------------------------------------------------------------------
303 \input{NumericPlots_labels}
304 \input{NumericPlots_TickLabels}
305
306 %
307 %\newlength{\picwidth}
308 \newlength{\CPicWidth}
309 \newlength{\CPicHeight}
310 \newlength{\StdLLX}\setlength{\StdLLX}{7ex +\baselineskip+2pt}
311 \newlength{\StdLLY}\setlength{\StdLLY}{2\baselineskip+1ex+2pt}
312 \newlength{\StdURX}\setlength{\StdURX}{2ex}
313 \newlength{\StdURY}\setlength{\StdURY}{0.5em}
314 \newlength{\OffsetWidth}
315 \newlength{\OffsetHeight}
316
317
318
319
320
321 % ==============================================================================
322 % ||
323 % || Axis (Scaling)
324 % ||
325 % ==============================================================================
326
327 \newcommand{\ScaleAxes}{
328 % calculate scaling:
329 % (<x> - xMin) * xDataCoordRatio + xCoordMin
330 % (<y> - yMin) * yDataCoordRatio + yCoordMin
331 % DataCoordRatio = (CoordMax-CoordMin)/(Max-Min)
332 % for logarithmic axes:
333 % (log(<x>) - log(xMin)) * xDataCoordRatio + xCoordMin
334 % (log(<y>) - log(yMin)) * yDataCoordRatio + yCoordMin
335 % DataCoordRatio = (CoordMax-CoordMin)/(log(Max)-log(Min))
336 \renewcommand{\xScaling}{\LogxAxis\space \NumDataPlotxMin\space sub
337 \NumDataPlotxDataCoordRatio\space mul \NumDataPlotxCoordMin\space add}
338 \renewcommand{\yScaling}{\LogyAxis\space \NumDataPlotyMin\space sub
339 \NumDataPlotyDataCoordRatio\space mul \NumDataPlotyCoordMin\space add}
340 \pstScalePoints(1.0, 1.0){\xScaling}{\yScaling}
341 }
342
343 % ==============================================================================
344 % ||
345 % || x-Axis
346 % ||
347 % ==============================================================================
348
349 \newcommand{\setxAxis}[1]{
350 % set the keys. xO and yO have to be set after xMin and yMin have been set!
351 % (xMin and yMin also set xO and yO but when xO and yO are set by the user,
352 % these values should be overwritten.)
353 \setkeys*[NumericDataPlot]{Axis}
354 [yMin, yMax, Dy, dy, yCoordMin, yCoordMax, yLog]{#1}
355 \setrmkeys[NumericDataPlot]{AxisWait}[yO, DDy]
356
357 % for logarithmic axes: calculate log(xMax), log(xMin), Dx=1, xO=ceil(xMin)
358 \ifNumericDataPlot@Axis@xLog
359 \FPln{\NumDataPlotBuffer}{\NumDataPlotxMax}
360 \FPdiv{\NumDataPlotxMax}{\NumDataPlotBuffer}{\NumDataPlotLnTen}
361 \FPround{\NumDataPlotxMax}{\NumDataPlotxMax}{3}
362 \FPln{\NumDataPlotBuffer}{\NumDataPlotxMin}
363 \FPdiv{\NumDataPlotxMin}{\NumDataPlotBuffer}{\NumDataPlotLnTen}
364 \FPround{\NumDataPlotxMin}{\NumDataPlotxMin}{3}
365 \renewcommand{\NumDataPlotDx}{1}
366 \FPtrunc{\NumDataPlotBuffer}{\NumDataPlotxMin}{0}
367 \FPadd{\NumDataPlotxO}{\NumDataPlotBuffer}{1}
368 \FPround{\NumDataPlotxO}{\NumDataPlotBuffer}{0}
369 \fi
370
371 \FPsub{\NumDataPlotxRange}{\NumDataPlotxMax}{\NumDataPlotxMin}
372 \FPsub{\NumDataPlotxCoordRange}{\NumDataPlotxCoordMax}{\NumDataPlotxCoordMin}
373 \FPdiv{\NumDataPlotxDataCoordRatio}{\NumDataPlotxCoordRange}{\NumDataPlotxRange}
374
375 % calculate number of ticks
376 \FPdiv{\xNrTicks}{\NumDataPlotxRange}{\NumDataPlotDx}
377 \FPtrunc{\xNrTicks}{\xNrTicks}{0}
378 % calculate number of tick labels
379 \FPdiv{\xNrTickLabels}{\NumDataPlotxRange}{\NumDataPlotDDx}
380 \FPtrunc{\xNrTickLabels}{\xNrTickLabels}{0}
381
382 % calculate dx (distance (in coordinates) between two ticks)
383 \FPmul{\NumDataPlotdx}{\NumDataPlotxDataCoordRatio}{\NumDataPlotDx}
384 \FPround{\NumDataPlotdx}{\NumDataPlotdx}{2}
385 % calculate dx for labels
386 \FPmul{\NumDataPlotdxLabels}{\NumDataPlotxDataCoordRatio}{\NumDataPlotDDx}
387 \FPround{\NumDataPlotdxLabels}{\NumDataPlotdxLabels}{2}
388
389 % calculate coordinates of x origin
390 \FPsub{\NumDataPlotBuffer}{\NumDataPlotxO}{\NumDataPlotxMin}
391 \FPmul{\NumDataPlotBuffer}{\NumDataPlotxDataCoordRatio}{\NumDataPlotBuffer}
392 \FPadd{\xCoordOrig}{\NumDataPlotBuffer}{\NumDataPlotxCoordMin}
393 \FPround{\xCoordOrig}{\xCoordOrig}{2}
394
395 % calculate number of ticks on right side of the origin
396 \FPsub{\TicksXRight}{\NumDataPlotxMax}{\NumDataPlotxO}
397 \FPdiv{\TicksXRight}{\TicksXRight}{\NumDataPlotDx}
398 \FPtrunc{\TicksXRight}{\TicksXRight}{0}
399 % calculate number of tick labels on right side of the origin
400 \FPsub{\TickLabelsXRight}{\NumDataPlotxMax}{\NumDataPlotxO}
401 \FPdiv{\TickLabelsXRight}{\TickLabelsXRight}{\NumDataPlotDDx}
402 \FPtrunc{\TickLabelsXRight}{\TickLabelsXRight}{0}
403
404 % calculate number of ticks on left side of the origin (number is negative!)
405 \FPsub{\TicksXLeft}{\NumDataPlotxMin}{\NumDataPlotxO}
406 \FPdiv{\TicksXLeft}{\TicksXLeft}{\NumDataPlotDx}
407 \FPsub{\TicksXLeft}{\TicksXLeft}{1}
408 \FPtrunc{\TicksXLeft}{\TicksXLeft}{0}
409 % calculate number of tick labels on left side of the origin (number is
410 % negative!)
411 \FPsub{\TickLabelsXLeft}{\NumDataPlotxMin}{\NumDataPlotxO}
412 \FPdiv{\TickLabelsXLeft}{\TickLabelsXLeft}{\NumDataPlotDDx}
413 \FPsub{\TickLabelsXLeft}{\TickLabelsXLeft}{1}
414 \FPtrunc{\TickLabelsXLeft}{\TickLabelsXLeft}{0}
415
416 \ScaleAxes{}
417 }
418
419
420 \newcommand{\plotxGridLine}[1]{
421 \FPsub{\NumDataPlotBuffer}{\NumDataPlotxCoordMax}{#1}
422 \FPsub{\NumDataPlotBufferI}{#1}{\NumDataPlotxCoordMin}
423 \FPmin{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotBufferI}
424 % \FPifneg{\NumDataPlotBuffer}
425 % \else
426 % plot grid line
427 \ifNumericDataPlot@xAxis@NoGrid
428 \else
429 \psline[style=GridSt](#1, \NumDataPlotyCoordMin)(#1, \NumDataPlotyCoordMax)
430 \fi
431 % plot tick for lower axis and upper axis - if desired
432 \ifNumericDataPlot@xAxis@NoTicks
433 \else
434 \ifthenelse{\boolean{PlotLowerAxis}}{
435 \psline[style=TickSt](#1, \NumDataPlotyCoordMin)
436 (!#1\space \NumDataPlotyCoordMin\space \xTickLength \space sub)
437 }{}
438 \ifthenelse{\boolean{PlotUpperAxis}}{
439 \psline[style=TickSt](#1, \NumDataPlotyCoordMax)
440 (!#1 \NumDataPlotyCoordMax\space \xTickLength \space add)
441 }{}
442 \fi
443 % \fi
444 }
445
446 \newcommand{\plotxSubGridLine}[1]{
447 \FPsub{\NumDataPlotBuffer}{\NumDataPlotxCoordMax}{#1}
448 \FPsub{\NumDataPlotBufferI}{#1}{\NumDataPlotxCoordMin}
449 \FPmin{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotBufferI}
450 \FPifneg{\NumDataPlotBuffer}
451 \else
452 % plot grid line
453 \ifNumericDataPlot@xAxis@NoGrid
454 \else
455 \psline[style=GridSt](#1,\NumDataPlotyCoordMin)(#1,\NumDataPlotyCoordMax)
456 \fi
457 \fi
458 }
459
460 % for logarithmic axes, LogxAxisLabel returns 10^#1. Normally it just returns
461 % #1.
462
463
464
465 \newcommand{\plotxTickLabels}[1]{
466 \FPadd{\NumDataPlotBuffer}{\TickLabelsXLeft}{1}
467 \FPround{\NumDataPlotBuffer}{\NumDataPlotBuffer}{0}
468
469 % plot ticks on right side of the origin
470 \mmultido{\n=\NumDataPlotxO+\NumDataPlotDDx}{\TickLabelsXRight}
471 {
472 \PutTickLabelXaxis[#1,x=\n]{\LogxAxisLabel{\n}}
473 }
474 % plot ticks on left side of the origin
475 \mmultido{\n=\NumDataPlotxO+\NumDataPlotDDx}{\NumDataPlotBuffer}
476 {
477 \PutTickLabelXaxis[#1,x=\n]{\LogxAxisLabel{\n}}
478 }
479 % plot tick at origin
480 \PutTickLabelXaxis[#1,x=\NumDataPlotxO]{\LogxAxisLabel{\NumDataPlotxO}}
481 }
482
483 \newcommand{\xLogSubGrid}[1]{
484 \ifNumericDataPlot@Axis@xLogNoSubGrid
485 \else
486 \ifNumericDataPlot@Axis@xLog
487 \multido{\iSubb=2+1}{8}{
488 \FPln{\NumDataPlotBuffer}{\iSubb}
489 \FPdiv{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotLnTen}
490 \FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotxDataCoordRatio}
491 \FPadd{\NumDataPlotTickPos}{#1}{\NumDataPlotBuffer}
492 \plotxSubGridLine{\NumDataPlotTickPos}
493 }
494 \fi
495 \fi
496 }
497
498 \newcommand{\plotxGrid}[1][NoGrid=false]{
499 \setkeys*[NumericDataPlot]{xAxis}{#1}
500
501 % plot gridline on right side of the origin
502 \mmultido{\n=\xCoordOrig+\NumDataPlotdx}{\TicksXRight}{
503 \plotxGridLine{\n}
504 \xLogSubGrid{\n}
505 }
506 % plot gridline on left side of the origin and at origin
507 \multido{\n=\xCoordOrig+\NumDataPlotdx}{\TicksXLeft}{
508 \plotxGridLine{\n}
509 }
510
511 \FPsub{\NumDataPlotBuffer}{\TicksXLeft}{1}
512 \FPround{\NumDataPlotBuffer}{\NumDataPlotBuffer}{0}
513 \multido{\n=\xCoordOrig+\NumDataPlotdx}{\NumDataPlotBuffer}{
514 \xLogSubGrid{\n}
515 }
516 }
517
518 \newcommand{\plotxAxis}[2][]{
519 \setkeys[NumericDataPlot]{putxLabel}{LabelSep}
520 \setkeys*[NumericDataPlot]{putxLabel}{#1}
521 \setrmkeys*[NumericDataPlot]{putxTickLabel}
522 \setrmkeys[NumericDataPlot]{xAxis}
523
524 % plot grid, ticks and ticklabels
525 \plotxGrid[#1]
526
527
528 % plot lower axis
529 \ifthenelse{\boolean{PlotLowerAxis}}
530 {
531 \psline{C-C}%
532 (\NumDataPlotxCoordMin, \NumDataPlotyCoordMin)%
533 (\NumDataPlotxCoordMax, \NumDataPlotyCoordMin)
534 \ifNumericDataPlot@xAxis@NoTickLabel
535 \else
536 \plotxTickLabels{ax=lower,#1}
537 \fi
538 % plot label
539 \ifNumericDataPlot@xAxis@NoLabel
540 \else
541 \PutLabelXaxis[ax=lower,#1]{#2}
542 \fi
543 %plot upper axis (boxed)
544 \ifthenelse{\boolean{PlotUpperAxis}}{
545 % plot upper axis
546 \psline{C-C}%
547 (\NumDataPlotxCoordMin,\NumDataPlotyCoordMax)%
548 (\NumDataPlotxCoordMax,\NumDataPlotyCoordMax)
549 }{}
550 }{
551 % plot upper axis (only upper axis)
552 \ifthenelse{\boolean{PlotUpperAxis}}{
553 % plot upper axis
554 \psline{C-C}%
555 (\NumDataPlotxCoordMin,\NumDataPlotyCoordMax)%
556 (\NumDataPlotxCoordMax, \NumDataPlotyCoordMax)
557 % plot ticklabels
558 \ifNumericDataPlot@xAxis@NoTickLabel
559 \else
560 \plotxTickLabels{ax=upper,#1}
561 \fi
562 % plot label
563 \ifNumericDataPlot@xAxis@NoLabel
564 \else
565 \PutLabelXaxis[ax=upper,#1]{#2}
566 \fi
567 }{}
568 }
569 }
570
571 \newcommand{\repeatxAxis}{\plotxAxis[NoLabel, NoTickLabel]{}}
572
573 % ==============================================================================
574 % ||
575 % || y-Axis
576 % ||
577 % ==============================================================================
578
579
580 \newcommand{\plotyTickLabels}[1]{
581 \FPadd{\NumDataPlotBuffer}{\TickLabelsYLeft}{1}
582 \FPround{\NumDataPlotBuffer}{\NumDataPlotBuffer}{0}
583 % plot ticks on right side of the origin
584 \mmultido{\n=\NumDataPlotyO+\NumDataPlotDDy}{\TickLabelsYRight}
585 {
586 \PutTickLabelYaxis[#1,y=\n]{\LogyAxisLabel{\n}}
587 }
588 % plot ticks on left side of the origin
589 \mmultido{\n=\NumDataPlotyO+\NumDataPlotDDy}{\NumDataPlotBuffer}
590 {
591 \PutTickLabelYaxis[#1,y=\n]{\LogyAxisLabel{\n}}
592 }
593 % plot tick at origin
594 \PutTickLabelYaxis[#1,y=\NumDataPlotyO]{\LogyAxisLabel{\NumDataPlotyO}}
595 }
596
597 \newcommand{\setyAxis}[1]{
598 % values from the x-axis must be ignored! If they weren't, the default values
599 % would be set!
600 \setkeys*[NumericDataPlot]{Axis}
601 [xO, xMin, xMax, xCoordMin, xCoordMax, Dx, dx, xLog]{#1}
602 \setrmkeys[NumericDataPlot]{AxisWait}[xO, DDx]
603
604 %\ifNumericDataPlot@Axis@yNearlyTight
605 % \FPifpos{\NumDataPlotyMax} \FPmul{\NumDataPlotyMax}{\NumDataPlotyMax}{1.1} \else \FPmul{\NumDataPlotyMax}{\NumDataPlotyMax}{0.9}\fi
606 % \FPifpos{\NumDataPlotyMin} \FPmul{\NumDataPlotyMin}{\NumDataPlotyMin}{0.9} \else \FPmul{\NumDataPlotyMin}{\NumDataPlotyMin}{1.1}\fi
607 % \fi
608
609 % for logarithmic axes: calculate log(xMax), log(xMin), Dy=1, xO=ceil(xMin)
610 \ifNumericDataPlot@Axis@yLog
611 \FPln{\NumDataPlotBuffer}{\NumDataPlotyMax}
612 \FPdiv{\NumDataPlotyMax}{\NumDataPlotBuffer}{\NumDataPlotLnTen}
613 \FPround{\NumDataPlotyMax}{\NumDataPlotyMax}{6}
614 \FPln{\NumDataPlotBuffer}{\NumDataPlotyMin}
615 \FPdiv{\NumDataPlotyMin}{\NumDataPlotBuffer}{\NumDataPlotLnTen}
616 \FPround{\NumDataPlotyMin}{\NumDataPlotyMin}{6}
617 \renewcommand{\NumDataPlotDy}{1}
618 \FPtrunc{\NumDataPlotBuffer}{\NumDataPlotyMin}{0}
619 \FPadd{\NumDataPlotyO}{\NumDataPlotBuffer}{1}
620 \FPround{\NumDataPlotyO}{\NumDataPlotyO}{0}
621 \fi
622
623 \FPsub{\NumDataPlotyRange}{\NumDataPlotyMax}{\NumDataPlotyMin}
624 \FPsub{\NumDataPlotyCoordRange}{\NumDataPlotyCoordMax}{\NumDataPlotyCoordMin}
625 \FPdiv{\NumDataPlotyDataCoordRatio}{\NumDataPlotyCoordRange}{\NumDataPlotyRange}
626
627 % calculate number of ticks
628 \FPdiv{\yNrTicks}{\NumDataPlotyRange}{\NumDataPlotDy}
629 \FPtrunc{\yNrTicks}{\yNrTicks}{0}
630 % calculate number of tick labels
631 \FPdiv{\yNrTickLabels}{\NumDataPlotyRange}{\NumDataPlotDDy}
632 \FPtrunc{\yNrTickLabels}{\yNrTickLabels}{0}
633
634 % calculate dy in coord -> distance between two ticks
635 \FPmul{\NumDataPlotdy}{\NumDataPlotyDataCoordRatio}{\NumDataPlotDy}
636 \FPround{\NumDataPlotdy}{\NumDataPlotdy}{2}
637 % calculate dyLabels in coord -> distance between two tick labels
638 \FPmul{\NumDataPlotdyLabels}{\NumDataPlotyDataCoordRatio}{\NumDataPlotDDy}
639 \FPround{\NumDataPlotdyLabels}{\NumDataPlotdyLabels}{2}
640
641 % calculate coordinates of y origin
642 \FPsub{\NumDataPlotBuffer}{\NumDataPlotyO}{\NumDataPlotyMin}
643 \FPmul{\NumDataPlotBuffer}{\NumDataPlotyDataCoordRatio}{\NumDataPlotBuffer}
644 \FPadd{\yCoordOrig}{\NumDataPlotBuffer}{\NumDataPlotyCoordMin}
645 \FPround{\yCoordOrig}{\yCoordOrig}{2}
646
647 % calculate number of ticks on right side of the origin
648 \FPsub{\TicksYRight}{\NumDataPlotyMax}{\NumDataPlotyO}
649 \FPdiv{\TicksYRight}{\TicksYRight}{\NumDataPlotDy}
650 \FPtrunc{\TicksYRight}{\TicksYRight}{0}
651 % calculate number of tick labels on right side of the origin
652 \FPsub{\TickLabelsYRight}{\NumDataPlotyMax}{\NumDataPlotyO}
653 \FPdiv{\TickLabelsYRight}{\TickLabelsYRight}{\NumDataPlotDDy}
654 \FPtrunc{\TickLabelsYRight}{\TickLabelsYRight}{0}
655
656 % calculate number of ticks on left side of the origin (number is negative!)
657 \FPsub{\TicksYLeft}{\NumDataPlotyMin}{\NumDataPlotyO}
658 \FPdiv{\TicksYLeft}{\TicksYLeft}{\NumDataPlotDy}
659 \FPsub{\TicksYLeft}{\TicksYLeft}{1}
660 \FPtrunc{\TicksYLeft}{\TicksYLeft}{0}
661 % calculate number of tick labels on left side of the origin (number is
662 % negative!)
663 \FPsub{\TickLabelsYLeft}{\NumDataPlotyMin}{\NumDataPlotyO}
664 \FPdiv{\TickLabelsYLeft}{\TickLabelsYLeft}{\NumDataPlotDDy}
665 \FPsub{\TickLabelsYLeft}{\TickLabelsYLeft}{1}
666 \FPtrunc{\TickLabelsYLeft}{\TickLabelsYLeft}{0}
667
668 % --- scaling ---
669 \ScaleAxes{}
670 }
671
672
673 \newcommand{\plotyGridLine}[1]{%
674 \FPsub{\NumDataPlotBuffer}{\NumDataPlotyCoordMax}{#1}
675 \FPsub{\NumDataPlotBufferI}{#1}{\NumDataPlotyCoordMin}
676 \FPmin{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotBufferI}
677 \FPifpos{\NumDataPlotBuffer}
678 % plot grid line
679 \ifNumericDataPlot@yAxis@NoGrid
680 \else
681 \psline[style=GridSt](\NumDataPlotxCoordMin, #1)(\NumDataPlotxCoordMax, #1)
682 \fi
683 % plot tick for lower axis and upper axis - if desired
684 \ifNumericDataPlot@yAxis@NoTicks
685 \else
686 \ifthenelse{\boolean{PlotLeftAxis}}{
687 \psline[style=TickSt](\NumDataPlotxCoordMin, #1)
688 (!\NumDataPlotxCoordMin\space \yTickLength \space sub #1)
689 }{}
690 \ifthenelse{\boolean{PlotRightAxis}}{
691 \psline[style=TickSt](\NumDataPlotxCoordMax, #1)
692 (!\NumDataPlotxCoordMax\space \yTickLength \space add #1)
693 }{}
694 \fi
695 \fi
696 }
697
698 \newcommand{\plotySubGridLine}[1]{%
699 % only used by yLogSubGrid
700 \FPsub{\NumDataPlotBuffer}{\NumDataPlotyCoordMax}{#1}
701 \FPsub{\NumDataPlotBufferI}{#1}{\NumDataPlotyCoordMin}
702 \FPmin{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotBufferI}
703 \FPifpos{\NumDataPlotBuffer}
704 % plot grid line
705 \ifNumericDataPlot@yAxis@NoGrid
706 \else
707 \psline[style=GridSt](\NumDataPlotxCoordMin, #1)(\NumDataPlotxCoordMax, #1)
708 \fi
709 \fi
710 }
711
712
713
714 \newcommand{\yLogSubGrid}[1]{%
715 % plots the subgrid for logarithmic axes, i.e. the grid between the two lines
716 % 10^x and 10^(x+1)
717 \ifNumericDataPlot@Axis@yLogNoSubGrid
718 \else
719 \ifNumericDataPlot@Axis@yLog
720 \multido{\iSubb=2+1}{8}{
721 \FPln{\NumDataPlotBuffer}{\iSubb}
722 \FPdiv{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotLnTen}
723 \FPmul{\NumDataPlotBuffer}{\NumDataPlotBuffer}{\NumDataPlotyDataCoordRatio}
724 \FPadd{\NumDataPlotTickPos}{#1}{\NumDataPlotBuffer}
725 \plotySubGridLine{\NumDataPlotTickPos}
726 }
727 \fi
728 \fi
729 }
730
731 \newcommand{\plotyGrid}[1][NoGrid=false]{
732 \setkeys*[NumericDataPlot]{yAxis}{#1}
733
734 % plot gridline on right side of the origin
735 \mmultido{\n=\yCoordOrig+\NumDataPlotdy}{\TicksYRight}{
736 \plotyGridLine{\n}
737 \yLogSubGrid{\n}
738 }
739 % plot gridline on left side of the origin
740 \multido{\n=\yCoordOrig+\NumDataPlotdy}{\TicksYLeft}{
741 \plotyGridLine{\n}
742 }
743 \FPsub{\NumDataPlotBuffer}{\TicksYLeft}{1}
744 \FPround{\NumDataPlotBuffer}{\NumDataPlotBuffer}{0}
745 \multido{\n=\yCoordOrig+\NumDataPlotdy}{\NumDataPlotBuffer}{
746 \yLogSubGrid{\n}
747 }
748 }
749
750 \newcommand{\plotyGridBoxed}{
751 % plot gridline on right side of the origin
752 \mmultido{\n=\yCoordOrig+\NumDataPlotdy}{\TicksYRight-1}{
753 \plotyGridLine{\n}
754 \yLogSubGrid{\n}
755 }
756 % plot gridline on left side of the origin
757 \multido{\n=\yCoordOrig+\NumDataPlotdy}{\TicksYLeft-1}{
758 \plotyGridLine{\n}
759 }
760 \FPsub{\NumDataPlotBuffer}{\TicksYLeft}{1}
761 \FPround{\NumDataPlotBuffer}{\NumDataPlotBuffer}{0}
762 \multido{\n=\yCoordOrig+\NumDataPlotdy}{\NumDataPlotBuffer}{
763 \yLogSubGrid{\n}
764 }
765 }
766
767
768 \newcommand{\plotyAxis}[2][]{
769 \setkeys[NumericDataPlot]{putyLabel}{LabelSep}
770 \setkeys*[NumericDataPlot]{putyLabel}{#1}
771 \setrmkeys*[NumericDataPlot]{putyTickLabel}
772 \setrmkeys[NumericDataPlot]{yAxis}
773
774 % plot grid
775 \plotyGrid[#1]
776
777 % plot left axis
778 \ifthenelse{\boolean{PlotLeftAxis}}
779 {
780 \psline{C-C}%
781 (\NumDataPlotxCoordMin,\NumDataPlotyCoordMin)%
782 (\NumDataPlotxCoordMin, \NumDataPlotyCoordMax)
783 \ifNumericDataPlot@yAxis@NoTickLabel
784 \else
785 \plotyTickLabels{ax=left,#1}
786 \fi
787 % plot right axis
788 \ifthenelse{\boolean{PlotRightAxis}}
789 {
790 \psline{C-C}%
791 (\NumDataPlotxCoordMax,\NumDataPlotyCoordMin)%
792 (\NumDataPlotxCoordMax, \NumDataPlotyCoordMax)
793 }{}
794 % --- label ---
795 \ifNumericDataPlot@yAxis@NoLabel
796 \else
797 \PutLabelYaxis[ax=left,#1]{#2}
798 \fi
799 }{
800 \ifthenelse{\boolean{PlotRightAxis}}
801 {
802 \psline{C-C}%
803 (\NumDataPlotxCoordMax,\NumDataPlotyCoordMin)%
804 (\NumDataPlotxCoordMax, \NumDataPlotyCoordMax)
805 \ifNumericDataPlot@yAxis@NoTickLabel
806 \else
807 \plotyTickLabels{ax=right,#1}
808 \fi
809 % --- label ---
810 \ifNumericDataPlot@yAxis@NoLabel
811 \else
812 \PutLabelYaxis[ax=right,#1]{#2}
813 \fi
814 }{}
815 }
816 }
817
818
819
820 % ==============================================================================
821 % ||
822 % || environment NumericDataPlot
823 % ||
824 % ==============================================================================
825
826
827 \newenvironment{NumericDataPlot}[3][]{%
828 %
829 \setlength{\OffsetWidth}{+\StdLLX +\StdURX}%
830 \setlength{\OffsetHeight}{+\StdLLY +\StdURY}%
831 % set standard values (they will be reset by setkeys if defined)
832 \psset{llx=-\StdLLX, lly=-\StdLLY, ury=\StdURY, urx=\StdURX}%
833 %
834 \setkeys[NumericDataPlot]{General}{#1}%
835 %
836 \setlength{\CPicWidth}{#2 - \OffsetWidth}%
837 \setlength{\CPicHeight}{#3 - \OffsetHeight}%
838 %%\setlength{\CPicWidth}{#2}
839 % calculate length of the yTicks:
840 % PicCoordWidth (=GxPicMax-GxPicMin) -> PicWidth (=#2)
841 % Length -> 1mm * yTickLength
842 % yTickLength must be negative
843 \setcounter{BufferCounter}{1*\ratio{#2}{1mm}}%
844 \FPsub{\NumDataPlotBuffer}{\NumDataPlotGxPicMax}{\NumDataPlotGxPicMin}%
845 \FPdiv{\NumDataPlotBufferI}{\NumDataPlotBuffer}{\theBufferCounter}%
846 \FPmul{\yTickLength}{\NumDataPlotBufferI}{\NumDataPlotGTickLength}%
847 \FPmul{\yTickLength}{\NumDataPlotBufferI}{-1}%
848 % calculate length of the xTicks
849 \setcounter{BufferCounter}{1*\ratio{#3}{1mm}}%
850 \FPsub{\NumDataPlotBuffer}{\NumDataPlotGyPicMax}{\NumDataPlotGyPicMin}%
851 \FPdiv{\NumDataPlotBufferI}{\NumDataPlotBuffer}{\theBufferCounter}%
852 \FPmul{\xTickLength}{\NumDataPlotBufferI}{\NumDataPlotGTickLength}%
853 \FPmul{\xTickLength}{\NumDataPlotBufferI}{-1}%
854 %
855 \begin{psgraph}%
856 [fillstyle=solid, fillcolor=gray, xAxis=false, yAxis=false]%
857 (\NumDataPlotGxPicMin, \NumDataPlotGyPicMin)(\NumDataPlotGxPicMin, \NumDataPlotGyPicMin)(\NumDataPlotGxPicMax, \NumDataPlotGyPicMax)%
858 {\CPicWidth}{\CPicHeight}%
859 }{%
860 \pstScalePoints(1.0, 1.0){0 add}{0 add}%
861 \end{psgraph}%
862 }
863 \psset{xunit=1mm, yunit=1mm, xAxisLabel={}, yAxisLabel={}}%
864 %
865
866 % ==============================================================================
867 % ||
868 % || legend
869 % ||
870 % ==============================================================================
871
872 \input{NumericPlots_legend}
873
874
875 % ============================================================================
876 % ||
877 % || Definition of styles
878 % ||
879 % ============================================================================
880
881 \input{NumericPlots_styles}
882
883
884
885 % ==============================================================================
886 % ||
887 % || commands...
888 % ||
889 % ==============================================================================
890
891 \input{NumericPlots_macros}
892
893
894
895 % ==============================================================================
896 % ||
897 % || package options ...
898 % ||
899 % ==============================================================================
900
901 \DeclareOptionX{beamer}{
902 \renewcommand{\StdLLY}{1.0cm}%
903 \renewcommand{\StdTickLabelOption}{\footnotesize}%
904 \setlength{\origXLabelSep}{1pt}%
905 }
906 \DeclareOptionX{xAxisStyle}[Boxed]{%
907 \presetkeys[NumericDataPlot]{xAxis}{AxisStyle=#1}{}%
908 }
909 \DeclareOptionX{yAxisStyle}[Boxed]{%
910 \presetkeys[NumericDataPlot]{yAxis}{AxisStyle=#1}{}%
911 }
912 \DeclareOptionX{LabelOption}[{}]{%
913 \renewcommand{\StdLabelOption}{#1}%
914 }
915 \DeclareOptionX{TickLabelOption}[{}]{%
916 \renewcommand{\StdTickLabelOption}{#1}%
917 }
918 \ProcessOptionsX
919
920 % \ProcessOptions
921
922 % ===========================================================================
923 % ||
924 % || set standard values for keys
925 % ||
926 % ===========================================================================
927 \presetkeys[NumericDataPlot]{Axis}{
928 xMax=100, xMin=0, Dx=10,
929 xCoordMax=\NumDataPlotGxPicMax, xCoordMin=\NumDataPlotGxPicMin,
930 xLog=false,
931 yMax=100, yMin=0, Dy=10,
932 yCoordMax=\NumDataPlotGyPicMax, yCoordMin=\NumDataPlotGyPicMin,
933 yLog=false,
934 yNearlyTight=false
935 }{}
936 \presetkeys[NumericDataPlot]{xAxis}{
937 NoGrid=false, NoTicks=false, NoLabel=false, NoTickLabel=false
938 }{}
939 \presetkeys[NumericDataPlot]{yAxis}{
940 NoGrid=false, NoTicks=false, NoLabel=false, NoTickLabel=false
941 }{}
942 % if xO/yO are not set they'll be set to xMin/yMin
943 \presetkeys[NumericDataPlot]{AxisWait}{%
944 xO=\NumDataPlotxMin, yO=\NumDataPlotyMin,%
945 DDx=\NumDataPlotDx, DDy=\NumDataPlotDy%
946 }{}
947
948 \presetkeys[NumericDataPlot]{General}{%
949 xPicMin=0, yPicMin=0, xPicMax=1000, yPicMax=1000, TickLength=2}{}%
950
951 \presetkeys[NumericDataPlot]{Legend}{%
952 LabelOrientation=l%
953 }{}%
954
955
956
957