我需要稍微移动带有误差线的 pstricks 图中的数据点以提高可读性。这些点彼此重叠,无法很好地区分。我尝试修改\def
fed 命令,但没有成功。最好的方法是给命令添加一个可选参数或第二个参数,\GetCoordinates
以在 x 轴上添加移位。
下面是包含数据的 MWE(1 和 2)以及它的外观(3 和 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}
答案1
像这样吗?
\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}