[pstricks] How to draw error bars in a diagram

Herbert Voss Herbert.Voss at alumni.TU-Berlin.DE
Mon Apr 28 21:42:40 CEST 2003


Martin Buchmann schrieb:

> So basically i would need something like make pstricks read data in the form:
> 
> x y dy- dy+
> 

here is a solution for data like this:

voss at maria:~/Documents> cat data.dat
-0.7 -0.4      0.1 0.5
-0.43 3        0   0.4
  1    4.6     -0.5 0.2
  1.2  2.3     -0.2 0.2
  1.7  3.9     -0.1 1
  2.7 -1.1     -0.2 0.3
  3.98 -0.7    -0.4 0
  4.5  0.7539  -0.5 0.4

the order of the lines is not important

Herbert


\documentclass[a4paper]{article}
\usepackage{pst-plot}
\usepackage{pst-node}
\makeatletter
\SpecialCoor
\def\errorLine{\@ifnextchar[{\pst at errorLine}{\pst at errorLine[]}}
\def\pst at errorLine[#1](#2)#3#4{{%
	\ifx#1\empty\else\psset{#1}\fi
	\pst at getcoor{#2}\pst at tempa
	\def\@errorMin{#3}
	\def\@errorMax{#4}
	\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 \@errorMin\space 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 \@errorMax\space add%
	)
}}
%
\def\GetCoordinates#1{\expandafter\GetCoordinates at i#1}
\def\GetCoordinates at i #1{\GetCoordinates at ii#1}
\def\GetCoordinates at ii#1 #2 #3 #4 #5 #6 #7 #8 {%
	\DoCoordinate{#2}{#4}%
	\errorLine[linecolor=red, linewidth=2pt](#2,#4){#6}{#8}% <<<<<
	\@ifnextchar D{\GetCoordinates at ii}{}%
}
\makeatother
\pagestyle{empty}
\begin{document}

\readdata{\Data}{data.dat}
\psset{dotscale=2}%
\begin{pspicture}(-1,-2)(5,5)
   \psgrid[subgriddiv=0, griddots=5]
   \def\DoCoordinate#1#2{\psdot(#1,#2)}%
   \GetCoordinates{\Data}
\end{pspicture}

\show\Data% only for the log file

\end{document}




More information about the PSTricks mailing list