[pstricks] TeX loop structures versus Postscript Loop Structures and Plotting
Buddy Ledger
buddyledger at gmail.com
Fri May 1 21:29:42 CEST 2009
>>/ 5. LineToXaxis should respect \psScalePoints. i.e.
/>>/ \psScalePoints(1,1){}{10 add} then the line should be drawn to (x,10)
/>>/ not (x,0) this allows for spatial velocity plots. I want to do scaled
/>>/ velocity plots on a spatial diagram.
/
>do you have a _short_ complete example for this?
Here is an example. The finished product would have geometric objects
representing physical objects in the xy plane.
Thus we can present velocity plots in the position which they occur.
This is useful for illustrating fluid mechanics behavior.
I think it will be rather simple to change the plotstyle and create an
option where Y=0 can be scaled acording to \psScalePoints
I'm looking into it right now.
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
\def\pserrorLine{\pst at object{pserrorLine}}
\def\pserrorLine at i(#1)#2#3{\begingroup
\use at par \pst at getcoor{#1}\pst at tempA
\def\ps at xErr{#2}\def\ps at yErr{#3}
\if\ps at yErr 0\relax \else
\psline(! /yDot \pst at tempA\space exch pop \pst at number\psyunit\space div def
/xDot \pst at tempA\space pop \pst at number\psxunit\space div def
xDot yDot yDot \ps at yErr\space mul add )
(! /yDot \pst at tempA\space exch pop \pst at number\psyunit\space div def
/xDot \pst at tempA\space pop \pst at number\psxunit\space div def
xDot yDot yDot \ps at yErr\space mul sub )
\fi
\if\ps at xErr 0\relax \else
\psline(! /yDot \pst at tempA\space exch pop \pst at number\psyunit\space div def
/xDot \pst at tempA\space pop \pst at number\psxunit\space div def
xDot xDot \ps at xErr\space mul add yDot )
(! /yDot \pst at tempA\space exch pop \pst at number\psyunit\space div def
/xDot \pst at tempA\space pop \pst at number\psxunit\space div def
xDot xDot \ps at xErr\space mul sub yDot )
\fi
\endgroup}
\def\psXaxesLine{\pst at object{psXaxesLine}}
\def\psXaxesLine at i(#1)#2{\begingroup
\use at par \pst at getcoor{#1}\pst at tempA
\def\ps at Yfunc{#2}
\psline{->}(!\pst at tempA\space pop \pst at number\psxunit\space div
0\space \ps at Yfunc)
(!\pst at tempA\space pop \pst at number\psxunit\space div
\pst at tempA\space exch pop \pst at number\psyunit\space div)
\endgroup}
\newcounter{loopcount}
\def\GetOneCoor{\pst at object{GetOneCoor}}
\def\GetOneCoor at i#1#2#3{%
%default options
\addbefore at par{dotstyle=o,PSxfunc=,PSyfunc=}
\use at par
\setcounter{loopcount}{0}
\xdef\plotxvalold{}
\xdef\plotyvalold{}
\def\numplot{#2}
\def\numplotmax{#3}
\expandafter\GetOneCoor at ii#1}
\def\GetOneCoor at ii#1{\GetOneCoor at iii#1}
\def\GetOneCoor at iii D #1 {%
\stepcounter{loopcount}
\ifnum\theloopcount=1 \def\plotxval{#1 }\fi
\ifnum\theloopcount=\numplot \def\plotyval{#1 }\fi
\ifnum\theloopcount=\numplotmax
%%%%%%%%%%%%%%%%%%
\ifx\plotyvalold\@empty \relax \else
\psset{linejoin=1}
\psline{-}(!\plotxvalold\space \gtc at PSxfunc\space
\plotyvalold\space \gtc at PSyfunc\space)%
(!\plotxval\space \gtc at PSxfunc\space
\plotyval\space \gtc at PSyfunc\space)
\fi%
\xdef\plotxvalold{\plotxval}
\xdef\plotyvalold{\plotyval}
%%%%%%%%%%%%%%%%%%%
%\psdot(!\plotxval\space \gtc at PSxfunc\space \plotyval\space
\gtc at PSyfunc)%
\pserrorLine(!\plotxval\space \gtc at PSxfunc\space \plotyval\space
\gtc at PSyfunc){\gtc at relxerr}{\gtc at relyerr}%
\psXaxesLine(!\plotxval\space \gtc at PSxfunc\space \plotyval\space
\gtc at PSyfunc){\gtc at PSyfunc}%input offset value
%\uput{0}[0](!\plotxval\space \gtc at PSxfunc\space \plotyval\space
\gtc at PSyfunc){% Data Labels Preliminary
%\psPrintCoor(!\plotxval\space \gtc at PSxfunc\space \plotyval\space
\gtc at PSyfunc){\gtc at relxerr}{\gtc at relyerr}}%
\setcounter{loopcount}{0}%
\fi%
\@ifnextchar D{\GetOneCoor at iii}{}}%
\pst at addfams{pst-GetCoor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%Keys for psPrintCoor
\define at key[psset]{pst-GetCoor}{PSfont}[Times-Roman]{\def\gtc at PSfont{/#1 }}
\define at key[psset]{pst-GetCoor}{valuewidth}[10]{\pst at getint{#1}\gtc at valuewidth
}
\define at key[psset]{pst-GetCoor}{fontscale}[10]{\pst at checknum{#1}\gtc at fontscale
}
\define at key[psset]{pst-GetCoor}{decimals}[-1]{\pst at getint{#1}\gtc at decimals }
\define at key[psset]{pst-GetCoor}{xShift}[0]{\def\gtc at xShift{#1}}
\define at key[psset]{pst-GetCoor}{yShift}[0]{\def\gtc at yShift{#1}}
\psset[pst-GetCoor]{xShift=0,yShift=0}
\psset[pst-GetCoor]{PSfont=Times-Roman,fontscale=10,valuewidth=10,decimals=-1}
\define at key[psset]{pst-GetCoor}{PSxfunc}{\def\gtc at PSxfunc{#1}}
\define at key[psset]{pst-GetCoor}{PSyfunc}{\xdef\gtc at PSyfunc{#1}}
\define at key[psset]{pst-GetCoor}{PSfunc}{\def\gtc at PSfunc{#1}}
\define at key[psset]{pst-GetCoor}{relxerr}{\def\gtc at relxerr{#1}}
\define at key[psset]{pst-GetCoor}{relyerr}{\def\gtc at relyerr{#1}}
\define at boolkey[psset]{pst-GetCoor}[Pst@]{xyPlotLabels}[true]{}%
\define at boolkey[psset]{pst-GetCoor}[Pst@]{science}[true]{%
\ifPst at science\def\gtc at Scin{true }\else\def\gtc at Scin{false }\fi}
\psset[pst-GetCoor]{science=false} %,xyPlotLabels=true}
\psset[pst-GetCoor]{PSfunc=dup mul exch dup mul add
sqrt,relxerr=0,relyerr=0,xyPlotLabels=false}
%\psset{dotstyle=square*,arrows=|-|} %Setup errorbar & dot style
\psset{PSxfunc=,PSyfunc=}
%%%%%%%%%%%%%%%%%%%%%%%%%%ENDOFKEYS
\makeatother
\begin{document}
\pagestyle{empty}
\pagenumbering{arabic}
\readdata[ignoreLines=0]{\dataC}{datafile.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}{!}
\psset{relxerr=0.0,relyerr=0.0}
\GetOneCoor[PSyfunc=10 add 3 div]{\dataC}{2}{2}
\psComment{->}(-8,14)(-5,3.5){Zero Y Velocity is plotted at Ys Spatial
Position}
\GetOneCoor[PSyfunc=10 add 3 div]{D -15 D 10}{2}{2}
\rput(-15,3){V=10m/s}
\end{psgraph}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
More information about the PSTricks
mailing list