pgfplots:图形覆盖的轴刻度

pgfplots:图形覆盖的轴刻度

如您所见,“20”数字被粉红色线覆盖:如何避免这种情况?

这是我的 MWE

\documentclass[12pt]{article}
\usepackage{pgfplots} 
\pgfplotsset{compat=newest}
\pgfplotsset{
  every mark/.append style={mark size=0.5pt},
  grid, grid style={dashed, draw=gray!10},
  legend image with text/.style={
        legend image code/.code={%
            \node[anchor=center] at (0.3cm,0cm) {#1};
        }
    },
}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
  legend pos=outer north east,
  legend cell align={left},
  grid, grid style=dashed,
  ymin=-6,ymax=6,
  xmax=55,xmin=0,  
  ytick={-5,-4,-3,-2,-1,0,1,2,3,4,5},
  xtick={5,10,15,20,25,30,35,40,45,50},  
  extra y ticks={0},
            width=14cm,
            height=7.5cm,
  axis lines = middle,
  set layers,
  x label style={at={(1,0.5)},right},
  y label style={at={(0,1)},above},
  xlabel={$x$},ylabel={$y$}, 
  style={thick}
               ]                
        \addplot+[only marks, mark=*,blue] table[x=A,y=C,col sep=comma] {potAF-BF.csv};
        \draw[pink,thick] (0,0.00059252) -- (16,-0.008131576);
        \draw[pink,thick] (17,-0.008676832) -- (18,-4.45194);
        \draw[pink,thick] (18,-4.45194) -- (19,-2.21057);
        \draw[pink,thick] (19,-2.21057) -- (20,0);
        \draw[pink,thick] (20,0) -- (22,4.51354);
        \draw[pink,thick] (22,4.51354) -- (23,0.00827042);
        \draw[pink,thick] (24,0.00784436) -- (50,-0.0032332);                                                                                                                                                                                                                                                                           
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

.csv 文件链接:https://www.transfernow.net/HgcaSv082020

答案1

只需使用将其向右移动的extra x ticks专用样式即可。extra x tick style

 extra x ticks={20}, 
 extra x tick style={xshift=6pt},

截屏

\documentclass[12pt]{article}
\usepackage{pgfplots} 
\pgfplotsset{compat=newest}
\pgfplotsset{
  every mark/.append style={mark size=0.5pt},
  grid, grid style={dashed, draw=gray!10},
  legend image with text/.style={
        legend image code/.code={%
            \node[anchor=center] at (0.3cm,0cm) {#1};
        }
    },
}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
  legend pos=outer north east,
  legend cell align={left},
  grid, grid style=dashed,
  ymin=-6,ymax=6,
  xmax=55,xmin=0,  
  ytick={-5,-4,-3,-2,-1,0,1,2,3,4,5},
  xtick={5,10,15,25,30,35,40,45,50}, 
  extra x ticks={20}, 
  extra x tick style={xshift=6pt},
  extra y ticks={0},
            width=14cm,
            height=7.5cm,
  axis lines = middle,
  set layers,
  x label style={at={(1,0.5)},right},
  y label style={at={(0,1)},above},
  xlabel={$x$},ylabel={$y$}, 
  style={thick}
               ]                
        \addplot+[only marks, mark=*,blue] table[x=A,y=C,col sep=comma] {potAF-BF.csv};
        \draw[pink,thick] (0,0.00059252) -- (16,-0.008131576);
        \draw[pink,thick] (17,-0.008676832) -- (18,-4.45194);
        \draw[pink,thick] (18,-4.45194) -- (19,-2.21057);
        \draw[pink,thick] (19,-2.21057) -- (20,0);
        \draw[pink,thick] (20,0) -- (22,4.51354);
        \draw[pink,thick] (22,4.51354) -- (23,0.00827042);
        \draw[pink,thick] (24,0.00784436) -- (50,-0.0032332);                                                                                                                                                                                                                                                                           
    \end{axis}
\end{tikzpicture}
\end{document}

答案2

您可以axis on top=true像这样使用该选项:

\documentclass[12pt]{article}
\usepackage{pgfplots} 
\pgfplotsset{compat=newest}
\pgfplotsset{
  every mark/.append style={mark size=0.5pt},
  grid, grid style={dashed, draw=gray!10},
  legend image with text/.style={
        legend image code/.code={%
            \node[anchor=center] at (0.3cm,0cm) {#1};
        }
    },
}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
  axis on top=true,
  legend pos=outer north east,
  legend cell align={left},
  grid, grid style=dashed,
  ymin=-6,ymax=6,
  xmax=55,xmin=0,  
  ytick={-5,-4,-3,-2,-1,0,1,2,3,4,5},
  xtick={5,10,15,20,25,30,35,40,45,50},  
  extra y ticks={0},
            width=14cm,
            height=7.5cm,
  axis lines = middle,
  set layers,
  x label style={at={(1,0.5)},right},
  y label style={at={(0,1)},above},
  xlabel={$x$},ylabel={$y$}, 
  style={thick}
               ]                
%        \addplot+[only marks, mark=*,blue] table[x=A,y=C,col sep=comma] {potAF-BF.csv};
        \draw[pink,thick] (0,0.00059252) -- (16,-0.008131576);
        \draw[pink,thick] (17,-0.008676832) -- (18,-4.45194);
        \draw[pink,thick] (18,-4.45194) -- (19,-2.21057);
        \draw[pink,thick] (19,-2.21057) -- (20,0);
        \draw[pink,thick] (20,0) -- (22,4.51354);
        \draw[pink,thick] (22,4.51354) -- (23,0.00827042);
        \draw[pink,thick] (24,0.00784436) -- (50,-0.0032332);                                                                                                                                                                                                                                                                           
    \end{axis}
\end{tikzpicture}
\end{document}

轴在上

相关内容