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

Buddy Ledger buddyledger at gmail.com
Fri May 1 23:18:25 CEST 2009


Here is the version I'll be using from now on.

Re-implimentation of LineToXAxis > adds optional baseline Y shift

Re-implimentation of LineToYAxis > adds optional baseline X shift

Minor change to \psScalePoints > save x,y operators for use (/xOper 
/yOper) in LineToXAxis and LineToYAxis

Buddy



\documentclass[]{article}

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

\begin{filecontents*}{datafile2.dat}
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
\end{filecontents*}
\makeatletter

\define at boolkey[psset]{pstricks-add}[Pst@]{ScyBase}[true]{}%
\define at boolkey[psset]{pstricks-add}[Pst@]{ScxBase}[true]{}%
\psset{ScyBase=true,ScxBase=true}

\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
    /xOper { #3\space x mul #1\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 \ifPst at ScyBase yOper \fi Lineto
    n { 2 copy moveto pop 0 \ifPst at ScyBase yOper \fi Lineto } repeat
    CP
    4 2 roll
    ArrowB
    2 copy moveto pop 0 \ifPst at ScyBase yOper \fi
    L
    pop pop } if}>

\def\psLineToYAxis at ii{%
\addto at pscode{\pst at cp \psline at iii \tx at LineToYAxis}%
\end at OpenObj}
%
\def\tx at LineToYAxis{LineToYAxis }
%
\pst at def{LineToYAxis}<{
NArray
n 0 eq not
  { n 1 eq { 0 0 /n 2 def } if
    ArrowA
    /n n 2 sub def
    CP 2 copy moveto exch pop 0 \ifPst at ScxBase xOper \fi exch Lineto
    n { 2 copy moveto exch pop 0 \ifPst at ScxBase xOper \fi exch Lineto } 
repeat
    CP
    4 2 roll
    ArrowB
    2 copy moveto exch pop 0 \ifPst at ScxBase xOper \fi exch
    L
    pop pop } if}>
%
\makeatother


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

\readdata[ignoreLines=0]{\dataA}{datafile2.dat}

\psset{xAxisLabel=x, %Setup for psgraph env
        yAxisLabel=y,
        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){5 add}{5 add 2 div}
\listplot[plotstyle=LineToXAxis,ScyBase=true]{\dataA}
\listplot[plotstyle=LineToYAxis,ScxBase=true]{\dataA}
\pstScalePoints(-1,1){5 add}{5 add 2 div}
\listplot[plotstyle=LineToXAxis,ScyBase=false]{\dataA}
\listplot[plotstyle=LineToYAxis,ScxBase=false]{\dataA}
\pstScalePoints(1,1){}{}
\end{psgraph}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}


More information about the PSTricks mailing list