![轴右侧的自定义标签](https://linux22.com/image/398856/%E8%BD%B4%E5%8F%B3%E4%BE%A7%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A0%87%E7%AD%BE.png)
我在自定义标签及其位置方面遇到了问题,尤其是坐标中有负值时。如果起始值为负,则无法获取 y 轴右侧的位置,并且其高度会偏移。您有解决方案吗?
% !TeX program = xelatex
\documentclass{scrartcl}
\usepackage{pstricks}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[ylabelPos=right](0,0)(3,3.4)
\rput(2,1){position ok}
\psline[linecolor=red,ylabelPos=right](0,0)(0,-1)(1,-1)
\end{pspicture}
%
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[yLabels={A,B,C,D},ylabelPos=right](0,0)(3,3.4)
\rput(2,1){position not ok}
\rput(2,0.5){labels on left side}
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\end{pspicture}
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[ylabelPos=right,Oy=-1](0,-1)(3,2.4)
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\rput(2,1){position ok}
\end{pspicture}
%
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[yLabels={A,B,C,D},ylabelPos=right](0,-1)(3,2.4)
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\rput(2,1){position not ok}
\rput(2,0.5){labels on left side}
\rput(2,0){and shifted down}
\end{pspicture}
Red Corner for Reference Position
\end{document}
答案1
将尽快修复:
\documentclass{scrartcl}
\usepackage{pstricks}
\usepackage{pst-plot}
\makeatletter\def\pst@vlabels#1#2#3#4{%
\ifSpecialLabelsDone\else
\ifx\empty\psk@yLabels
\ifdim#1=\z@\else
\ifx#2\empty\else\ifdim#1>\z@ \advance#1 by -7\pslinewidth\else\advance#1 by 7\pslinewidth\fi\fi
\pst@cnta=#1\relax % % Distance (in sp) to end.
\divide\pst@cnta\psk@dy\relax% % Number of ticks/labels
\ifnum\pst@cnta=\z@\else
\pst@dima=\psk@dy sp% % Space between ticks.
\ifodd\number\psk@labels\else\ifPst@yAxis\pst@@vlabels\fi
\fi
\showoriginfalse
\fi
\fi
\else
\pstFPsub\pst@pmtempa{#4}{#3}%
\pstFPDiv\pst@pmtempb{\pst@pmtempa}{\psk@Dy}%
\pstFPadd\pst@pmtempc{\pst@pmtempb}{-1}%
\pstFPadd\pst@pmtempd{\pst@pmtempb}{1}%
\ifdim\pst@pmtempb pt < \z@
\def\pst@pmtempe{\pst@int{\pst@pmtempc}}\else\def\pst@pmtempe{\pst@int{\pst@pmtempd}}\fi
\multido{\nA=0+1,\rA=#3+\psk@Dy}{\pst@pmtempe}{%
\ifdim \nA pt < \z@ \def\nB{-\nA}\else \def\nB{\nA}\fi
\ifnum\psk@ylabelPos=0
\uput{\psylabelsep}[180]{\pst@yLabelsRot}(0,\rA){%
\strut\expandafter\psvlabel\expandafter{\psPutYLabel{\nB}}}%
\else
\uput{\psylabelsep}[0]{\pst@yLabelsRot}(0,\rA){%
\strut\expandafter\psvlabel\expandafter{\psPutYLabel{\nB}}}%
\fi
}%
\SpecialLabelsDonetrue
\fi
\fi
}
\makeatother
\begin{document}
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[ylabelPos=right](0,0)(3,3.4)
\rput(2,1){position ok}
\psline[linecolor=red,ylabelPos=right](0,0)(0,-1)(1,-1)
\end{pspicture}
%
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[yLabels={A,B,C,D},ylabelPos=right](0,0)(3,3.4)
\rput(2,1){position not ok}
\rput(2,0.5){labels on left side}
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\end{pspicture}
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[ylabelPos=right,Oy=-1](0,-1)(3,2.4)
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\rput(2,1){position ok}
\end{pspicture}
%
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[yLabels={,A,B,C,D},ylabelPos=right](0,-1)(3,2.4)
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\rput(2,1){position not ok}
\rput(2,0.5){labels on left side}
\rput(2,0){and shifted down}
\end{pspicture}
Red Corner for Reference Position
\begin{pspicture}(-1,-3)(3,2.4)
\psaxes[yLabels={,A,B,C,D}](0,-1)(3,2.4)
\psline[linecolor=red](0,0)(0,-1)(1,-1)
\rput(2,1){position not ok}
\rput(2,0.5){labels on left side}
\rput(2,0){and shifted down}
\end{pspicture}
\end{document}