Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ncar!csn!boulder!news!grunwald From: grunwald@foobar.colorado.edu (Dirk Grunwald) Newsgroups: comp.text.tex Subject: Re: Out of memory grinding PiCTeX pictures: what should I do? Message-ID: <1991Apr29.155942.27717@colorado.edu> Date: 29 Apr 91 15:59:42 GMT References: <32370@usc> <32384@usc> Sender: news@colorado.edu (The Daily Planet) Reply-To: grunwald@foobar.colorado.edu Organization: University of Colorado at Boulder Lines: 667 In-Reply-To: tli@almaak.usc.edu's message of 28 Apr 91 08:26:00 GMT Nntp-Posting-Host: foobar.colorado.edu >>>>> On 28 Apr 91 08:26:00 GMT, tli@almaak.usc.edu (Tony Li) said: TL> Nntp-Posting-Host: almaak.usc.edu TL> Process your data with Matlab, get out PostScript, and include that in TL> your TeX document. --- An exceptionally poor choice if you want to include TeXisms in your pictures. In any case, you'd be much better of using the FREE software 'xgraph'. Here's some useful macros. ezplot.tex - specify plots in simple format, e.g. \ezplot size 4in, point at 10, 20, x from 0 to 0.60, y from 0 to 45 / texpictex.tex - draw *lines* (not curves) using tpic specials - speeds things up and saves memory. Most output drivers handle tpic. If not, they're readily available errorbars.tex - draw plots w/marks and/or error bars, syntax is: % \plotWith mark M at x1 y1 x2 y2 .... xN yN / % \plotWithErrorBars mark M at % x1 y1 e1 % x2 y2 e2 .... xN yN eN % / % multiplot.tex - simplified form of above if x-increment is constant: % \multiplot from x-origin by x-increment at list-of-data-values / ----------------------------------------------------------------------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'ezplot.tex' <<'END_OF_FILE' X% X% ezplot.tex -- establishes the plot parameters for a PiCTeX X% plot using the ``natural'' units for your data X% X% Example: X% \ezplot size 4in, point at 10, 20, x from 0 to 0.60, y from 0 to 45 / X% Yields: X% \setcoordinatesystem units <289.07999pt, 2.97765pt> X% \setplotarea x from 0 0.60, y from 0 to 45 X% X% Given the size of the x-axis of the final plot and the bounds, X% it selects the X and Y scaling constants for \setcoordinatesystem X% and then sets up the plotarea. X% X% It would be possible to use this same information to number X% an \axis, but it appears that \axis uses the width of X% the axis numbers to position the axis label. This means it X% ends up looking ugly if you do this. X% X% By default, the plot uses the Golden Ratio for the aspect X% ratio, making the plot somewhat wider than tall. See ``The Visual X% Display of Quantitative Information'' by Tufte for the justification. X% X% Dirk Grunwald 8/31/88 X% X% This version uses the PiCTeX \Divide macro to do a high precision X% division. X% X% X\def\makebangletter{\catcode`\!=11\relax} X\def\makebangother{\catcode`\!=12\relax} X% X\makebangletter X% X%\def\ezplotAspectRatio{0.61803} X\def\ezplotAspectRatio{1} X\def\setAspectRatio#1{\def\ezplotAspectRatio{#1}} X% X% gobble first arg, decide on following parse X% X\def\ezplot size #1, {% X \def\!ezplotPoint{\setcoordinatesystem units <\dimen8, \dimen9>}% X \dimen1=#1 \relax X \!ifnextchar{p}{\!ezplota}{\!ezplotb}} X% X% recognize ``point at'' X% X\def\!ezplota point at (#1,#2), {% X \message{EzPlot sez: point is at #1,#2}% X \def\!ezplotPoint{\setcoordinatesystem units <\dimen8, \dimen9>% X point at #1 #2 } X \!ezplotb} X% X% recognize ``x from ... /" X% X\def\!ezplotb x from #1 to #2, y from #3 to #4 /{% X \dimen8=\dimen1% X \dimen4=#1 pt X \dimen5=#2 pt X \advance \dimen5 by -\dimen4 % Compute x span (in points) X \Divide <\dimen8> by <\dimen5> forming <\dimen4> % Compute points/x-span X \dimen8=\dimen4 X \dimen9=\dimen1% And now do the same for Y X \dimen9=\ezplotAspectRatio \dimen9 \relax% X \dimen4=#3 pt \relax% X \dimen5=#4 pt \relax% X \advance \dimen5 by -\dimen4 X \Divide <\dimen9> by <\dimen5> forming <\dimen4> % Compute points/x-span X \dimen9=\dimen4 X\message{EzPlot sez: units are X\the\dimen8 \space on X and \the\dimen9 \space on Y} X\!ezplotPoint X\setplotarea x from #1 to #2, y from #3 to #4 X} X% X\makebangother END_OF_FILE if test 2350 -ne `wc -c <'ezplot.tex'`; then echo shar: \"'ezplot.tex'\" unpacked with wrong size! fi # end of 'ezplot.tex' fi if test -f 'texpictex.tex' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'texpictex.tex'\" else echo shar: Extracting \"'texpictex.tex'\" \(7432 characters\) sed "s/^X//" >'texpictex.tex' <<'END_OF_FILE' X% X% texpictex.tex -- The following macros over-ride certain definitions in the X% PiCTeX macro package. The net effect is that line-drawing is done using X% the \special's used by texpic (tpic). Several DVI printers understand X% and handle these specials. X% X% Currently, only straight lines are translated. Recently, I added a X% clipping routine to clip to the bounding box. X% X% If people extend this to included elliptic circles and quadratics, X% please forward the extensions to me (quads are used in the \arrow X% macro, making them very slow). X% X% Dirk Grunwald X% Univ. of Illinois X% grunwald@m.cs.uiuc.edu X% X\def\makebangletter{\catcode`\!=11\relax} X\def\makebangother{\catcode`\!=12\relax} X% X\makebangletter X% X% The units that texpic deals in. You should define it this way instead X% of simply saying ``0.001in'' because the difference in resolution X% actually makes a big difference X% X\newdimen\!tpu X\!tpu=1in X\divide\!tpu by 1000 X%%% X%% \!maptpus -- map a PiCTeX dimension to a TeXPiC dimension X%% using the \!tpu conversion factor. X%% X%% uses: dimen0 X%% X\def\!maptpus#1#2 {\dimen0=#1\divide \dimen0 by \!tpu #2=\dimen0} X% X% ** \setplotsymbol ({PLOTSYMBOL} [ ] < , >) X% ** Save PLOTSYMBOL away in an hbox for use with curve plotting routines X% ** See Subsection 5.2 of the manual. X\def\setplotsymbol(#1#2){% X \!setputobject{#1}{#2} X \setbox\!plotsymbol=\box\!putobject% X \!plotsymbolxshift=\!xshift X \!plotsymbolyshift=\!yshift X% X% Additions: compute size of dot, convert to TPUs and issue a pensize X% X \!dimenB=\wd\!plotsymbol X \!dimenC=\ht\!plotsymbol X \advance\!dimenC by \dp\!plotsymbol X \ifdim\!dimenB<\!dimenC \!dimenF=\!dimenC \else \!dimenF=\!dimenB\fi X \!maptpus{\!dimenF}{\!countC} X \special{pn \the\!countC} X \ignorespaces} X X\setplotsymbol({\fiverm .})% ** initialize plotsymbol X X% ** The following routine is used to draw a "solid" line between (xS,yS) X% ** and (xE,yE). Points are spaced nearly every \plotsymbolspacing length X% ** along the line. X% X% Note: this is a replacement for PicTeX \!linearsolid. X% If line clipping is enabled, the line to be drawn is X% clipped using \!clipline. If there's anything left X% to draw after clipping, it's drawn. If clipping is off, X% the line is simply drawn. In either case, line drawing X% is done by \!texpicline. X% X\def\!linearsolid{% X% \typeout{Using texpictex linearsolid}% X \let\!nextLinearAct=\!texpicline X \expandafter\ifx \!initinboundscheck \relax X \else \!clipline \if!InBounds \else \let\!nextLinearAct=\relax \fi \fi% X \!nextLinearAct% X} X% X% Texpic has increasing origin in the upper left corner, while X% pictex has origin in bottom left corner. Ergo, we flip the signs X% for y-coordinates. X% X\def\!texpicline{% X\advance\!xS by -\!xorigin X\advance\!xE by -\!xorigin X\advance\!yS by -\!yorigin X\advance\!yE by -\!yorigin X\!maptpus{\!xS}{\!countC} \!maptpus{\!yS}{\!countD} \!countD=-\!countD% X\special{pa \the\!countC \space \the\!countD}% X\!maptpus{\!xE}{\!countC} \!maptpus{\!yE}{\!countD} \!countD=-\!countD% X\special{pa \the\!countC \space \the\!countD}\special{fp}% X\ignorespaces} X% X%%% X% Code to support line clipping X% X% Line clipping routine. Clips to bounding box specified X% by (!checkleft, !checkbot) and (!checkright, !checktop). X% Note that this box is only defined if \initboundscheckon X% has been called. X% X% The clipping algorithm was published in ACM TOG Vol 3 No 1 X% by people at Berkeley, but I've forgotten the complete reference. X% This was translated from a version I wrote in C. X% X%% X% After calling \!cliplines, !InBounds tells you if the line contains X% any points within the clipping window. X% X\newif\if!InBounds X% X%% X% \!clipt -- this corresponds to the routine by the same name X% in the published algorithm. X% X% Dimens used are descibed below. All are grouped and know that X% PiCTeX doesn't use dimen0..9. Variable names are taken from X% the TOG article. The junk on the r.h.s. is indenting information X% X% Globals: dimen8 corresponds to t0 X% dimen9 corresponds to t1 X% X% clipt dimen0 corresponds to p X% dimen1 corresponds to q X% dimen2 corresponds to r X% X% !fastclip Uses bounding boxes X% X% !clipline passes dimen3 to clipt as p X% passes dimen4 to clipt as q X% uses dimen0, dimen2 X% X% X\def\!clipt#1#2{% X \dimen0=#1 \relax \dimen1=#2 \relax X \ifdim \dimen0 < \!zpt% >0 X \!divide{\dimen1}{\dimen0}{\dimen2}% X \ifdim \dimen2 > \dimen9% >1 X \global\!InBoundsfalse X \else% =1 X \ifdim \dimen2 > \dimen8 \dimen8=\dimen2 \fi X \fi% <1 X \else \ifdim \dimen0 > \!zpt% =0>1 X \!divide{\dimen1}{\dimen0}{\dimen2}% X \ifdim \dimen2 < \dimen8% >2 X \global\!InBoundsfalse X \else% =2 X \ifdim \dimen2 < \dimen9 \dimen9=\dimen2 \fi X \fi% <2 X \else% =1 X \ifdim \dimen1 < \!zpt \global\!InBoundsfalse \fi X \fi% <1 X \fi% <0 X} X% X% fastclipcheck X% X\def\!fastclip#1#2{% X \ifdim #1<\!checkleft \global\!InBoundsfalse \else X \ifdim #1>\!checkright \global\!InBoundsfalse \else X \ifdim #2<\!checkbot \global\!InBoundsfalse \else X \ifdim #2>\!checktop \global\!InBoundsfalse \else X \fi X \fi X \fi X \fi} X% X% clipline - clip a line to the current bounding box. X% assumes line is in (!xS, !yS) and extends to (!xE,!yE) and that X% \!xdiff and \!ydiff has been set up. This is normally done X% in \!lstart. X% X% \!clipline first checks to see if the start & end points are X% conainted in the clipping box. If the simple compare works, X% then no clipping is done, else \!doclip is called to X% do the actually clipping computations. X% X\def\!clipline{% X \!!initinboundscheck X \!InBoundstrue X \!fastclip{\!xS}{\!yS}% X \!fastclip{\!xE}{\!yE}% X \if!InBounds\else\!doclip\fi} X% X\def\!doclip{% X\begingroup% X \global\!InBoundstrue% X \dimen8=0pt X \dimen9=1pt X % X \dimen3=-\!xdiff X \dimen4=\!xS \advance\dimen4 by -\!checkleft% fromX-minX X \!clipt{\dimen3}{\dimen4}% X% X \if!InBounds% 0 X \dimen3=\!xdiff X \dimen4=\!checkright \advance\dimen4 by -\!xS% maxX - fromX X \!clipt{\dimen3}{\dimen4}% X% X \if!InBounds% 1 X% X \dimen3=-\!ydiff X \dimen4=\!yS \advance\dimen4 by -\!checkbot% fromY-minY X \!clipt{\dimen3}{\dimen4}% X% X \if!InBounds% 2 X% X \dimen3=\!ydiff X \dimen4=\!checktop \advance\dimen4 by -\!yS% maxY-fromY X \!clipt{\dimen3}{\dimen4}% X% X \if!InBounds% 3 X \dimen0=1pt X% X% The following \if's truncate the line based on the solution X% to the parametric solution to the bounding box. X% X% Note that we don't have a \!multiply, the equivilent to \!divide. X% The code below compute X * Y as (x / ( 1/ Y)), which is far X% from optimal. X% X \ifdim\dimen9 < \dimen0% 4 X \ifdim\dimen9=\!zpt% handle multiply by zero X \global\!xE=\!xS X \global\!yE=\!yS X \!InBoundsfalse% X \else X \!divide{\dimen0}{\dimen9}{\dimen2}% X% X \dimen3=\!xdiff \!divide{\dimen3}{\dimen2}{\dimen4}% X \global\!xE=\dimen4 \global\advance\!xE by \!xS X% X \dimen3=\!ydiff \!divide{\dimen3}{\dimen2}{\dimen4}% X \global\!yE=\dimen4 \global\advance\!yE by \!yS X \fi X \fi% 4 X \ifdim\dimen8 > \!zpt% 4 X \!divide{\dimen0}{\dimen8}{\dimen2}% X% X \dimen3=\!xdiff \!divide{\dimen3}{\dimen2}{\dimen4}% X \global\advance\!xS by \dimen4 X% X \dimen3=\!ydiff \!divide{\dimen3}{\dimen2}{\dimen4}% X \global\advance\!yS by \dimen4 X \fi% 4 X \fi% 3 X \fi% 2 X \fi% 1 X \fi% 0 X\endgroup} X% X\makebangother END_OF_FILE if test 7432 -ne `wc -c <'texpictex.tex'`; then echo shar: \"'texpictex.tex'\" unpacked with wrong size! fi # end of 'texpictex.tex' fi if test -f 'errorbars.tex' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'errorbars.tex'\" else echo shar: Extracting \"'errorbars.tex'\" \(4959 characters\) sed "s/^X//" >'errorbars.tex' <<'END_OF_FILE' X% X% TeX macros to plot error bars with the PicTeX macros. X% X% These macros are largely derived from the examples in the back X% of the PiCTeX manual. X% X% To plot with a mark at each data point, simply say X% X% \plotWith mark M at x1 y1 x2 y2 .... xN yN / X% X% where "M" is a mark character {e.g. $\bullet$} X% X% To include error bars in the plot, say: X% X% \plotWithErrorBars mark M at X% x1 y1 e1 X% x2 y2 e2 .... xN yN eN X% / X% X% The line-breaking isn't needed. Marks are placed on the graph X% at (xi, yi) for each data point. Vertical error bars are drawn X% from (xi, yi + ei) to (xi, yi - ei). X% X% The cross-bar at the top and bottom of the error bars is normally X% 5 pts, but can be changed by setting the \crossbarlength dimen. X% X% X% Dirk Grunwald Apr 20 1988 X% X% X\def\makebangletter{\catcode`\!=11\relax} X\def\makebangother{\catcode`\!=12\relax} X X\makebangletter X% X\newdimen\crossbarsize X\crossbarsize=2.5pt X% X% macros for local dimens. Previous values preserved across plots. X% X\def\!lastPlotX{\dimen1} X\def\!lastPlotY{\dimen2} X\def\!tmpPlotX{\dimen3} X\def\!tmpPlotY{\dimen4} X\def\!tmpPlotXX{\dimen5} X\def\!tmpPlotYY{\dimen6} X\def\crossbarheight{\dimen7} X\def\crossbarwidth{\dimen8} X% X\newif\ifconnectpoints X\connectpointstrue X% X\newif\ifmentionplot X\mentionplotfalse X% X% X\newif\if!PointInBounds X% X\def\!checkPoint#1#2{% X \ifdim #1<\!checkleft\global\!PointInBoundsfalse\else% X \ifdim #1>\!checkright\global\!PointInBoundsfalse\else% X \ifdim #2<\!checkbot\global\!PointInBoundsfalse\else% X \ifdim #2>\!checktop\global\!PointInBoundsfalse\else% X \!PointInBoundstrue% X \fi% X \fi% X \fi% X \fi} X% X\def\!plotErrorBar#1 #2 #3 #4{% X \crossbarheight=\Ydistance{#3} X \expandafter\ifx \!initinboundscheck \relax X \put {#4} at {#1} {#2} X \put { X \vbox{% X \hsize=2\crossbarsize X \hrule height \!plotsymbolyshift X \vskip -.5\!plotsymbolyshift X \centerline{\vrule width \!plotsymbolyshift height 2\crossbarheight} X \nointerlineskip X \vskip -.5\!plotsymbolyshift X \hrule height \!plotsymbolyshift} X } at {#1} {#2} X \else% X %% X %% The data value goes at (#1,#2), which we convert to dimens X %% X \!tmpPlotX=\Xdistance{#1}% X \!tmpPlotY=\Ydistance{#2}% X \!checkPoint{\!tmpPlotX}{\!tmpPlotY}% X \if!PointInBounds% X \put {#4} at {#1} {#2} X \fi X %% X %% top flat part of cross X %% X \setdimensionmode X \!tmpPlotXX=\!tmpPlotX X \advance\!tmpPlotX by -\crossbarsize X \advance\!tmpPlotXX by \crossbarsize X \advance\!tmpPlotY by \crossbarheight X % X \setdimensionmode X \plot {\!tmpPlotX} {\!tmpPlotY} {\!tmpPlotXX} {\!tmpPlotY} / X % X % bottom cross stroke X % X \!tmpPlotYY=\!tmpPlotY X \advance\!tmpPlotYY by -2\crossbarheight X \plot {\!tmpPlotX} {\!tmpPlotYY} {\!tmpPlotXX} {\!tmpPlotYY} / X % X % down stroke X % X \advance\!tmpPlotX by \crossbarsize X \plot {\!tmpPlotX} {\!tmpPlotY} {\!tmpPlotX} {\!tmpPlotYY} / X \setcoordinatemode X \fi% X} X% X\def\plotWithErrorBars mark #1 at #2 #3 #4 {% X \begingroup X \def\!errorBarMark{#1}% X % X % plot first point X % X \begingroup X \setsolid X \!plotErrorBar {#2} {#3} {#4} {\!errorBarMark} X \endgroup X \!lastPlotX=\Xdistance{#2} X \!lastPlotY=\Ydistance{#3} X \futurelet\nextcharacter\!plotErrorBarLoop} X% X\def\!plotErrorBarLoop{% X \if/\nextcharacter X \let\!plotErrorBarAction=\!plotErrorBarFinish% X \else X \let\!plotErrorBarAction=\!plotErrorBarContinued% X \fi X \!plotErrorBarAction} X% X\def\!plotErrorBarFinish/ {\endgroup} X% X\def\!plotErrorBarContinued#1 #2 #3 {% X \begingroup% X \setsolid X \!plotErrorBar {#1} {#2} {#3} {\!errorBarMark} X \endgroup% X \!tmpPlotX = \Xdistance{#1} X \!tmpPlotY = \Ydistance{#2} X \setdimensionmode X \ifconnectpoints% X \plot {\!lastPlotX} {\!lastPlotY} {\!tmpPlotX} {\!tmpPlotY} / X \fi% X \setcoordinatemode X \!lastPlotX = \!tmpPlotX X \!lastPlotY = \!tmpPlotY X \futurelet\nextcharacter\!plotErrorBarLoop} X% X\def\plotWith mark #1 at #2 #3 {% X \begingroup% X \def\!plotWithMark{#1}% X % X % plot first point X % X \ifmentionplot\message{Plot {\!plotWithMark} at #2 #3}\fi% X \put {\!plotWithMark} at {#2} {#3} X \!lastPlotX=\Xdistance{#2}% X \!lastPlotY=\Ydistance{#3}% X \futurelet\nextcharacter\!plotWithLoop} X% X\def\!plotWithLoop{% X \if/\nextcharacter% X \let\!plotWithAction=\!plotWithFinish% X \else% X \let\!plotWithAction=\!plotWithContinued% X \fi% X \!plotWithAction} X% X\def\!plotWithFinish/ {\endgroup} X% X\def\!plotWithContinued#1 #2 {% X \ifmentionplot\message{ Plot {\!plotWithMark} at #1 #2}\fi% X \put {\!plotWithMark} at {#1} {#2} X \!tmpPlotX = \Xdistance{#1}% X \!tmpPlotY = \Ydistance{#2}% X \setdimensionmode% X \ifconnectpoints% X \plot {\!lastPlotX} {\!lastPlotY} {\!tmpPlotX} {\!tmpPlotY} / X \fi% X \setcoordinatemode% X \!lastPlotX = \!tmpPlotX% X \!lastPlotY = \!tmpPlotY% X \futurelet\nextcharacter\!plotWithLoop% X} X X\makebangother END_OF_FILE if test 4959 -ne `wc -c <'errorbars.tex'`; then echo shar: \"'errorbars.tex'\" unpacked with wrong size! fi # end of 'errorbars.tex' fi if test -f 'multiplot.tex' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'multiplot.tex'\" else echo shar: Extracting \"'multiplot.tex'\" \(1356 characters\) sed "s/^X//" >'multiplot.tex' <<'END_OF_FILE' X% X% \!multiplot from x-origin by x-increment at list-of-data-values / X% X% following requires errorbar.tex X% X\makebangletter X X\newdimen\!multiputBy X X\def\multiplot from #1 by #2 at #3 {% X\begingroup X\!lastPlotX=\Xdistance{#1}% X\!multiputBy=\Xdistance{#2}% X\!lastPlotY=\Ydistance{#3}% X\def\!plotWithMark{\relax}% X\futurelet\nextcharacter\!multiplotLoop} X% X\def\multiplotWith mark #1 from #2 by #3 at #4 {% X\begingroup% X\def\!plotWithMark{#1}% X\!multiputBy=\Xdistance{#3}% X\!lastPlotX=\Xdistance{#2}% X\!lastPlotY=\Ydistance{#4}% X\ifmentionplot\message{Plot {\!plotWithMark} at #2 #4}\fi% X\put {\!plotWithMark} at {#2} {#4} X\futurelet\nextcharacter\!multiplotLoop} X% X\def\!multiplotLoop{% X \if/\nextcharacter% X \let\!multiplotAction=\!multiplotFinish% X \else% X \let\!multiplotAction=\!multiplotContinued% X \fi% X \!multiplotAction% X} X% X\def\!multiplotFinish/ {\endgroup} X% X\def\!multiplotContinued#1 {% X \!tmpPlotX = \!lastPlotX% X \advance\!tmpPlotX by \!multiputBy% X \!tmpPlotY = \Ydistance{#1}% X%% X \setdimensionmode% X \expandafter\ifx\!plotWithMark\relax X \else \put {\!plotWithMark} at {\!tmpPlotX} {\!tmpPlotY} \fi X \plot {\!lastPlotX} {\!lastPlotY} {\!tmpPlotX} {\!tmpPlotY} / X \setcoordinatemode% X%% X \!lastPlotX=\!tmpPlotX% X \!lastPlotY = \!tmpPlotY% X \futurelet\nextcharacter\!multiplotLoop} X X\makebangother END_OF_FILE if test 1356 -ne `wc -c <'multiplot.tex'`; then echo shar: \"'multiplot.tex'\" unpacked with wrong size! fi # end of 'multiplot.tex' fi echo shar: End of shell archive. exit 0