1

I'm trying to make a graph where the maximum and minimum of the plotted data are reflected on an axis and the axis line stops after that value. Although sometimes I want noisy data to appear at larger/smaller values.

I tried to offset the axis as was suggested in this post. The problem you can see is that in this case I want the axis to go from -0.1 to -0.7 with ticks at these positions. The problem is that if you have noisy data it gets clipped after ymin and ymax.

I've provided a manually edited example on the bottom.

\documentclass{standalone}
\usepackage{pgfplots} 

\newlength\xaxisoffset
\setlength\xaxisoffset{-10pt}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        every non boxed x axis/.style={ %Shifts the x axis downwards
            x axis line style={yshift=\xaxisoffset},
            xticklabel style={yshift=\xaxisoffset},
            xtick style={very thin,yshift=\xaxisoffset},
        }, 
        xmin = -.09, xmax=.09,
        axis x line=bottom,
        axis y line*=left,
        ymin = -0.7, ymax = -0.08,
        ytick={-.1, -.7},
        ]
        \addplot[smooth, black] table[x=B, y=R_NL] {SV018_RR2B2.dat};
        \end{axis};
    \end{tikzpicture}
\end{document}

plot from code plot I want

2
  • Clipping can be disabled by option clip=false.
  • The order of magnitude of the x labels (·10-2) is moved down twice; x tick scale label style={yshift=-\xaxisoffset} compensates it.

Full example file:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\newlength\xaxisoffset
\setlength\xaxisoffset{-40pt}

\begin{document}
  \begin{tikzpicture}  
    \begin{axis}[    
      clip=false,  
      every non boxed x axis/.style={% Shifts the x axis downwards  
        x axis line style={yshift=\xaxisoffset},    
        xticklabel style={yshift=\xaxisoffset},    
        x tick scale label style={yshift=-\xaxisoffset},    
        xtick style={very thin,yshift=\xaxisoffset},    
      },   
      xmin = -.09, xmax=.09, 
      axis x line=bottom,  
      axis y line*=left,  
      ymin = -0.7, ymax = -0.1,  
      ytick={-.1, -.7},  
    ]    
      \addplot[smooth, black] coordinates {  
         (-.08, -.5) (-.06, -.8) (-.04, -.5) (-.02, -.7)  
         (-.0, -.1) (.02, -.4) (.04, -.05) (.06, -.2) (.08, -.75)  
      };  
    \end{axis};    
  \end{tikzpicture}  
\end{document}

Result

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.