[pstricks] TeX loop structures versus Postscript Loop Structures and Plotting

Buddy Ledger buddyledger at gmail.com
Fri May 1 22:26:47 CEST 2009


Herbert,

Here is my version of the LineToXAxis/psScalePoints Implimentation.  
Didn't take as long as I thought.

Buddy


\documentclass[]{article}

\usepackage{pst-all}
\usepackage{pst-func}
\usepackage{pstricks-add}
\usepackage{filecontents}

\begin{filecontents*}{datafile.dat}
-5 0
-4 9
-3 16
-2 21
-1 24
0 25
1 24
2 21
3 16
4 9
5 0
\end{filecontents*}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%Keys for psPrintCoor
\define at boolkey[psset]{pstricks-add}[Pst@]{ScyBase}[true]{%
  \ifPst at ScyBase\def\psk at ScyBase{true }\else\def\psk at ScyBase{false }\fi}
\psset{ScyBase=true}
%%%%%%%%%%%%%%%%%%%%%%%%%%ENDOFKEYS

\def\pstScalePoints(#1,#2)#3#4{%
%  xScale | yScale | xOperator | yOperator  
% the operators can be any Postscript code
\pst at def{ScalePoints}<%
    /y ED /x ED
    /yOper {#4\space y mul #2\space mul} def
    counttomark dup dup cvi eq not { exch pop } if
    /m exch def /n m 2 div cvi def
    n {
      #4\space y mul #2\space mul m 1 roll
      #3\space x mul #1\space mul m 1 roll
      /m m 2 sub
      def } repeat>%
}
\def\psLineToXAxis at ii{%
\addto at pscode{\pst at cp \psline at iii \tx at LineToXAxis}%
\end at OpenObj}
%
\def\tx at LineToXAxis{LineToXAxis }
%
\pst at def{LineToXAxis}<{%
NArray
n 0 eq not
  { n 1 eq { 0 0 /n 2 def } if
    ArrowA
    /n n 2 sub def
    CP 2 copy moveto pop 0 \psk at ScyBase { yOper } if Lineto
    n { 2 copy moveto pop 0 \psk at ScyBase { yOper } if Lineto } repeat
    CP
    4 2 roll
    ArrowB
    2 copy moveto pop 0 \psk at ScyBase { yOper } if
    L
    pop pop } if}>
\makeatother


\begin{document}
\pagestyle{empty}
\pagenumbering{arabic}

\readdata[ignoreLines=0]{\dataC}{datafile.dat}
\psset{xAxisLabel=y, %Setup for psgraph env
        yAxisLabel=V,
        xAxisLabelPos=,
        yAxisLabelPos=}
\begin{figure}
\centering
\begin{psgraph}%
[arrows=->,Dx=1,Dy=1,xsubticks=0,ysubticks=0]%
(0,0)(-15,0)(15,15){5in}{!}
\pstScalePoints(1,1){10 sub 2 div}{5 add 2 div}
\listplot[plotstyle=LineToXAxis,ScyBase=true]{\dataC}
\pstScalePoints(1,1){10 add 2 div}{5 add 2 div}
\listplot[plotstyle=LineToXAxis,ScyBase=false]{\dataC}
\pstScalePoints(1,1){}{}
\end{psgraph}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}


More information about the PSTricks mailing list