3

As you can see, the "20" number is overlayed by the pink line: how can avoid this?

This is my 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}

enter image description here

Link to the .csv file: https://www.transfernow.net/HgcaSv082020

4
  • Why are you plotting the data file with marks only, and then draw the lines manually after? Aug 7, 2020 at 20:56
  • Your file cannot be downloaded without being registered. Put it somewhere else!
    – AndréC
    Aug 7, 2020 at 21:11
  • @AndréC try now! Aug 7, 2020 at 21:18
  • @hpekristiansen whoops I didn't think it was enough delete the option only marks Aug 7, 2020 at 21:19

2 Answers 2

3

Just use extra x ticks with a dedicated style extra x tick style that shifts it to the right.

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

screenshot

\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}
3
  • How can I hide that vertical line above the number "20"? Aug 7, 2020 at 21:41
  • 1
    Try this extra x tick style= {shift={(6pt,-2pt)}, tickwidth=0cm, grid=none},
    – AndréC
    Aug 7, 2020 at 22:08
  • Thank you very much! Aug 8, 2020 at 10:47
3

You can use the axis on top=true option like this:

\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}

Axis on top

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.