3

I need to shift the data points in a pstricks plot with error bars slightly to improve readability. The points lay on each other and can not be good differenciated. I tried to modifiy the \deffed commands, but without succes. Best would be to have a optional or second argument to the \GetCoordinates command to add a shift at the x-Axis.

Here is a MWE with the data (1 and 2) and how it should look like (3 and 4):

\RequirePackage{filecontents}
\begin{filecontents*}{Data1.txt}
    5 7.346642472 0.570377917 -0.5703779173
    5.5 7.568566113 0.575130876 -0.5751308769
\end{filecontents*}
\begin{filecontents*}{Data2.txt}
    5 7.042472165 0.370377917 -0.370377917
    5.5 7.925676113 0.325130876 -0.325130876
\end{filecontents*}
\begin{filecontents*}{Data3.txt}
    6.075 7.346642472 0.570377917 -0.5703779173
    6.5075 7.568566113 0.575130876 -0.5751308769
\end{filecontents*}
\begin{filecontents*}{Data4.txt}
    5.925 7.042472165 0.370377917 -0.370377917
    6.425 7.925676113 0.325130876 -0.325130876
\end{filecontents*}
% !TeX program = xelatex
\documentclass[12pt]{article}
\usepackage[x11names]{xcolor}
\usepackage{pstricks,pst-plot,pst-bar,pst-fill}


\SpecialCoor
\pagestyle{empty}
\parindent=0pt
\usepackage{pst-node}
\makeatletter
\SpecialCoor
\def\errorLine{\@ifnextchar[{\pst@errorLine}{\pst@errorLine[]}}
\def\pst@errorLine[#1](#2)#3#4{{%
        \ifx#1\empty\else\psset{#1}\fi
        \pst@getcoor{#2}\pst@tempb
        \def\@errorMin{#3}
        \def\@errorMax{#4}
        \psline{|*-|*}%
        (!%
        /yDot \pst@tempb exch pop \pst@number\psyunit div def
        /xDot \pst@tempb pop \pst@number\psxunit div def
        xDot yDot \@errorMin\space add%
        )(!%
        /yDot \pst@tempb exch pop \pst@number\psyunit div def
        /xDot \pst@tempb pop \pst@number\psxunit div def
        xDot yDot \@errorMax\space add%
        )
}}
%
\def\GetCoordinates#1{\expandafter\GetCoordinates@i#1}
\def\GetCoordinates@i #1{\GetCoordinates@ii#1}
\def\GetCoordinates@ii#1 #2 #3 #4 #5 #6 #7 #8 {%
    \DoCoordinate{#2}{#4}%
    \errorLine[linecolor=black, linewidth=0.8pt,tbarsize=2pt 4](#2,#4){#6}{#8}% <<<<<
    \@ifnextchar D{\GetCoordinates@ii}{}}
\makeatother
\def\DoCoordinate#1#2{\psdot(#1,#2)}



\begin{document}
\psset{yunit=0.2}
\begin{pspicture}(4.5,0)(9.5,42)
\psaxes[Ox=40,Dx=10,dx=1,Oy=0,Dy=500,dy=5,%
ysubticks=2,axesstyle=frame,tickstyle=inner,ticksize=6pt,tickwidth=0.8pt]{->}(4,0)(9.5,42)

%Bad ones
\readdata{\OHrot}{Data1.txt}
\readdata{\Nrot}{Data2.txt}
\psset{linecolor=DarkSeaGreen3}
\GetCoordinates{\OHrot}
\psset{linecolor=LightBlue3}
\GetCoordinates{\Nrot}

% Shifted ones
\readdata{\OHrot}{Data3.txt}
\readdata{\Nrot}{Data4.txt}
\psset{linecolor=DarkSeaGreen3}
\GetCoordinates{\OHrot}
\psset{linecolor=LightBlue3}
\GetCoordinates{\Nrot}
\end{pspicture}
\end{document}
2

something like this?

\RequirePackage{filecontents}
\begin{filecontents*}{Data1.txt}
    5 7.346642472 0.570377917 -0.5703779173
    5.5 7.568566113 0.575130876 -0.5751308769
\end{filecontents*}
\begin{filecontents*}{Data2.txt}
    5 7.042472165 0.370377917 -0.370377917
    5.5 7.925676113 0.325130876 -0.325130876
\end{filecontents*}
\begin{filecontents*}{Data3.txt}
    6.075 7.346642472 0.570377917 -0.5703779173
    6.5075 7.568566113 0.575130876 -0.5751308769
\end{filecontents*}
\begin{filecontents*}{Data4.txt}
    5.925 7.042472165 0.370377917 -0.370377917
    6.425 7.925676113 0.325130876 -0.325130876
\end{filecontents*}
% !TeX program = xelatex
\documentclass[12pt]{article}
\usepackage[x11names]{xcolor}
\usepackage{pstricks,pst-plot,pst-bar,pst-fill}


\SpecialCoor
\pagestyle{empty}
\parindent=0pt
\usepackage{pst-node}
\makeatletter
\SpecialCoor
\def\errorLine{\@ifnextchar[{\pst@errorLine}{\pst@errorLine[]}}
\def\pst@errorLine[#1](#2)#3#4{{%
        \ifx#1\empty\else\psset{#1}\fi
        \pst@getcoor{#2}\pst@tempb
        \def\@errorMin{#3}
        \def\@errorMax{#4}
        \psline{|*-|*}%
        (!%
        /yDot \pst@tempb exch pop \pst@number\psyunit div def
        /xDot \pst@tempb pop \pst@number\psxunit div \XShift\space sub def
        xDot yDot \@errorMin\space add%
        )(!%
        /yDot \pst@tempb exch pop \pst@number\psyunit div def
        /xDot \pst@tempb pop \pst@number\psxunit div  \XShift\space sub def
        xDot yDot \@errorMax\space add%
        )
}}
%
\def\GetCoordinates[#1]#2{\def\XShift{#1}\expandafter\GetCoordinates@i#2}
\def\GetCoordinates@i #1{\GetCoordinates@ii#1}
\def\GetCoordinates@ii#1 #2 #3 #4 #5 #6 #7 #8 {%
    \DoCoordinate{#2}{#4}%
    \errorLine[linecolor=black, linewidth=0.8pt,tbarsize=2pt 4](#2,#4){#6}{#8}% <<<<<
    \@ifnextchar D{\GetCoordinates@ii}{}}
\makeatother
\def\DoCoordinate#1#2{\psdot(!#1 \XShift\space sub #2)}



\begin{document}
\psset{yunit=0.2}
\begin{pspicture}(4.5,0)(9.5,42)
\psaxes[Ox=40,Dx=10,dx=1,Oy=0,Dy=500,dy=5,%
ysubticks=2,axesstyle=frame,tickstyle=inner,ticksize=6pt,tickwidth=0.8pt]{->}(4,0)(9.5,42)

%Bad ones
\readdata{\OHrot}{Data1.txt}
\readdata{\Nrot}{Data2.txt}
\psset{linecolor=DarkSeaGreen3}%
\GetCoordinates[0.1]{\OHrot}

\psset{linecolor=LightBlue3}%
\GetCoordinates[-0.1]{\Nrot}
%
% Shifted ones
\readdata{\OHrot}{Data3.txt}
\readdata{\Nrot}{Data4.txt}
\psset{linecolor=DarkSeaGreen3}%
\GetCoordinates[0.1]{\OHrot}
\psset{linecolor=LightBlue3}%
\GetCoordinates[-0.1]{\Nrot}
\end{pspicture}
\end{document}

enter image description here

| improve this answer | |
  • Thanks, I modified your solution after tex.stackexchange.com/q/49056/63420 and added another main command like this: \DeclareRobustCommand\GetCoordinates{\@ifnextchar[{\@@GetCoordinates}{\@GetCoordinates}}. One with the old command, the other with your command, which works fine. – Niklas Jun 26 '19 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.