[pstricks] GetCoorinates Modification

Buddy Ledger buddyledger at gmail.com
Wed Apr 22 08:11:24 CEST 2009


Herbert,

I noticed you posted the GetCoordinates Modification to the examples 
page.  I have since updated the code to make errorbars optional via 
setting relative error to zero.  This allows either x, y, xy or no error 
bars to be drawn on the figure.  I've also taken the explicit arrow 
style out of the definition of pserrorLine so that it can be changed via 
psset before the psgraph environment.  I've also been playing with 
providing data labels in the form of coordinate pairs, not very elegant 
yet but it works (sort of).

Buddy

\documentclass[]{article}

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

\begin{filecontents*}{datafile.dat}
Vc CH1DiaMT3 CH2DiaMS3 CH3DiaMT6 CH4DiaMS6
1.600000E+000 9.826193E+000 6.984904E+000 8.066498E+000 4.960284E+000
1.800000E+001 1.163769E+001 9.443092E+000 1.030773E+001 5.544281E+000
2.800000E+001 1.590967E+001 1.898143E+001 1.214513E+001 5.621518E+000
\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 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 )
 \fi
 \if\ps at xErr 0\relax \else
 \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 )
  \fi
\endgroup}

\newcounter{loopcount}
\def\GetCoordinates#1#2#3#4#5{%
\setcounter{loopcount}{0}
\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}
        \uput{0.5}[45](!\plotxval \plotyval){% Data Labels Preliminary
         $($\makebox[2em][l]{\psPrintValue[decimals=1]{\plotxval}}
         $,$\makebox[2em][l]{\psPrintValue[decimals=1]{\plotyval}}$)$}
        \setcounter{loopcount}{0}
      \fi\fi\fi%
 \@ifnextchar D{\GetCoordinates at ii}{}}
\makeatother

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

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

\psset{dotstyle=square*,arrows=|-|} %Setup errorbar & dot style

\readdata[ignoreLines=1]{\dataA}{datafile.dat}

\begin{figure}
\centering
\begin{psgraph}[Dx=5,Dy=5,xsubticks=5,ysubticks=5](0,0)(0,0)(40,40){5.3in}{5.3in}
\GetCoordinates{\dataA}{0.1}{0}{2}{5}
\end{psgraph}
\caption{Error Bars.}
\end{figure}
\end{document}



More information about the PSTricks mailing list