[pstricks] GetCoorinates Modification

Herbert Voss Herbert.Voss at FU-Berlin.DE
Tue Apr 14 23:13:28 CEST 2009


Buddy Ledger schrieb:
> Please help me.  I've modified one of the macro examples from the Latex
> Graphics Companion (See below).  My objective was to specify the relative
> error in the measurements via passing to the macro rather than from the
> file.  This is for singular measurements where the equipment error is
> estimated a priori.  Also I wanted to be able to plot data files in the form
> (x y1 y2 y3 ... yn) much like the pstricks-add listplot function.
> 
> The code actually works for simply formatted data files example:
> 1 2 3 4
> 2 3 4 5
> 3 4 5 6
> 4 5 6 7
> 
> Will plot fine with
> GetCoordinates{\dataA}{relxerr}{relyerr}{plotno}{totalcol}.  However my data
> files are formatted as such:
> 1.00E+001 2.00E+001 3.00E+001 4.00E+001
> 2.00E+001 3.00E+001 4.00E+001 5.00E+001
> 3.00E+001 4.00E+001 5.00E+001 6.00E+001
> 4.00E+001 5.00E+001 6.00E+001 7.00E+001

TeX cannot handle such values, but PostScript can,
the reason why you should use the coordinates in
PS notation (see code)

Herbert

\documentclass{article}
\begin{filecontents}{doterrorbar.dat}
1.00E+001 2.00E+001 3.00E+001 4.00E+001
2.00E+001 3.00E+001 4.00E+001 5.00E+001
3.00E+001 4.00E+001 5.00E+001 6.00E+001
4.00E+001 5.00E+001 6.00E+001 7.00E+001
\end{filecontents}

\usepackage{pstricks-add}

\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}%
 \psline{|-|}(! /yDot \pst at tempA exch pop \pst at number\psyunit div def
      /xDot \pst at tempA pop \pst at number\psxunit div def
      xDot yDot yDot \ps at yErr\space mul add )
     (! /yDot \pst at tempA exch pop \pst at number\psyunit div def
      /xDot \pst at tempA pop \pst at number\psxunit div def
      xDot yDot yDot \ps at yErr\space mul sub )
 \psline{|-|}(! /yDot \pst at tempA exch pop \pst at number\psyunit div def
      /xDot \pst at tempA pop \pst at number\psxunit div def
      xDot xDot \ps at xErr\space mul add yDot )
     (! /yDot \pst at tempA exch pop \pst at number\psyunit div def
      /xDot \pst at tempA pop \pst at number\psxunit div def
      xDot xDot \ps at xErr\space mul sub yDot )
\endgroup}

\newcounter{loopcount}
\def\GetCoordinates#1#2#3#4#5{%
\def\relxerr{#2}\def\relyerr{#3}\def\numplot{#4}\def\numplotmax{#5}
\expandafter\GetCoordinates at i#1}

\def\GetCoordinates at i#1{\GetCoordinates at ii#1}
\def\GetCoordinates at ii D #1 {%
 \stepcounter{loopcount}
 \ifnum\theloopcount=1 \def\plotxval{#1 }\else
    \ifnum\theloopcount=\numplot \def\plotyval{#1 }\else
      \ifnum\theloopcount=\numplotmax
        \psdot(!\plotxval \plotyval)
        \pserrorLine(!\plotxval \plotyval){\relxerr}{\relyerr}%
        \setcounter{loopcount}{0}
      \fi\fi\fi%
 \@ifnextchar D{\GetCoordinates at ii}{}}
\makeatother

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

\psset{xAxisLabel=Centerline Velocity[m/s],
  yAxisLabel=Vibration Amplitude [\%Dia],
  xAxisLabelPos={c,-0.5in},
  yAxisLabelPos={-0.5in,c},
  lly=-0.55in,llx=-0.55in,ury=0.25in,urx=0.15in}

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

\begin{figure}
\centering
\begin{psgraph}[Dx=5,Dy=5,xsubticks=0,ysubticks=0](0,0)(0,0)(40,40){5.3in}{5.3in}

\GetCoordinates{\dataA}{0.01}{0.1}{2}{4}

\end{psgraph}
\caption{Error Bars.}
\end{figure}

\end{document}



More information about the PSTricks mailing list