Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I successfully swapped my axis over earier and managed to get it scaled fine. I changed my mind and then changed it again so since then I've been spending hours trying to get this to work

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usepackage{siunitx}
\pgfplotsset{compat=1.7}

\begin{document}


\begin{tikzpicture}
\begin{axis}[    xticklabel={\pgfmathparse{(\tick)}\num[round-mode=places, round-precision=3]{\pgfmathresult}},
scaled y ticks=false,
 xlabel={Resonant Magnetic Field [mT]}, ylabel={Residuals [MHz]}]
\addplot[mark size=0.5, only marks,
      error bars/.cd,
        y dir=both, y explicit,
      ]
   table [y error index=2]
   {residuals_glycerin.txt};
   \addplot[mark size = 0.5, only marks,color=black]
    table [x index = 0, y index= 1]
    {residuals_glycerin.txt}; 
    \draw[ultra thin,gray] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0); 

\end{axis}
\end{tikzpicture}


\end{document}

Can someone please tell me why I am getting this error and how to fix it? I have checked the examples and none of them helped.

    -0.00106 328.43799 0.00092
-0.00038 328.18900 0.00092
0.00113 327.92099 0.00092
0.00057 327.70099 0.00092
0.00194 327.43600 0.00092
0.00246 327.19101 0.00092
-0.00389 327.10599 0.00092
0.00005 326.54800 0.00092
-0.00162 326.82001 0.00092
-0.00003 326.54999 0.00092
0.00057 326.30301 0.00092
0.00027 326.07700 0.00092
share|improve this question
1  
The y value 0 is somewhere a few meters below your plot. Where should that gray line lie exactly? –  Qrrbrbirlbel Mar 12 '13 at 21:01
    
@Qrrbrbirlbel This is actually the answer to Magpie's question: pgfplots cannot handle the case where a value is several meters outside of the visible area. Perhaps it should at least provide a readable error message. –  Christian Feuersänger Mar 12 '13 at 21:43
    
@Magpie writing \pgfmathparse{(\tick)} does not seem to have any useful effect, except that \pgfmathparse on its own can also produce dimension too large if \tick becomes larger than 16000. You can safely use \tick directly (instead of \pgfmathresult) –  Christian Feuersänger Mar 12 '13 at 21:44
    
@ChristianFeuersänger sorry I am confused. Which bit should I be getting rid of? I changed it to this xticklabel={\num[round-mode=places, round-precision=3]}, and it still won't compile. –  Magpie Mar 12 '13 at 22:45
    
Sorry, I meant \num[round-mode=places, round-precision=3]{\tick}. (see also the answer of @Qrrbrbirlbel) –  Christian Feuersänger Mar 13 '13 at 20:50

2 Answers 2

I'm assuming you want to draw a vertical line at the postion x=0. For that, you have to change your \draw command to

\draw[ultra thin,gray] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax}); 

(change xmin and xmax to ymin and ymax, and swap the coordinate components.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usepackage{siunitx}
\pgfplotsset{compat=1.7}

\begin{document}


\begin{tikzpicture}
\begin{axis}[    xticklabel={\pgfmathparse{(\tick)}\num[round-mode=places, round-precision=3]{\pgfmathresult}},
scaled x ticks=false,
 xlabel={Resonant Magnetic Field [mT]}, ylabel={Residuals [MHz]}]
\addplot[mark size=0.5, only marks,
      error bars/.cd,
        y dir=both, y explicit,
      ]
   table [y error index=2]
   {
   -0.00106 328.43799 0.00092
-0.00038 328.18900 0.00092
0.00113 327.92099 0.00092
0.00057 327.70099 0.00092
0.00194 327.43600 0.00092
0.00246 327.19101 0.00092
-0.00389 327.10599 0.00092
0.00005 326.54800 0.00092
-0.00162 326.82001 0.00092
-0.00003 326.54999 0.00092
0.00057 326.30301 0.00092
0.00027 326.07700 0.00092
};
   \addplot[mark size = 0.5, only marks,color=black]
    table [x index = 0, y index= 1]
    {
    -0.00106 328.43799 0.00092
-0.00038 328.18900 0.00092
0.00113 327.92099 0.00092
0.00057 327.70099 0.00092
0.00194 327.43600 0.00092
0.00246 327.19101 0.00092
-0.00389 327.10599 0.00092
0.00005 326.54800 0.00092
-0.00162 326.82001 0.00092
-0.00003 326.54999 0.00092
0.00057 326.30301 0.00092
0.00027 326.07700 0.00092
}; 
\draw[ultra thin,gray] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax}); 

\end{axis}
\end{tikzpicture}


\end{document}
share|improve this answer
    
Nah I was trying to do something else but I need to edit my question because it had the wrong data in. I just realised when I got rid of the grey line I could suddenly compile. Any idea why that would be? –  Magpie Mar 13 '13 at 0:19
    
@Magpie: Yes, because of what Christian Feuersänger and Qrrbbrbirbel have been saying: The line in your code is far too far below the plot. –  Jake Mar 13 '13 at 7:04

The y  value of your grey line is zero (0).

This is far below the actual plot (ymin is at 325.839784).
This is too far away for TeX’s mathematical engine which is not built for such great lengths. Besides, the line would have missed your paper by over six meters.
In addition to that, TikZ or pgfplots don’t check whether your line is actually visible in the plot (it would have been cropped away/clipped either way).

You will either need to set ymin=0 to use a y  value of 0 or a different value for y.

In the example below I have chosen the current ymin and added some text and changed the line thickness compared to your example.

In a comment Christian Feuersänger wrote:

[W]riting \pgfmathparse{(\tick)} does not seem to have any useful effect, except that \pgfmathparse on its own can also produce dimension too large if \tick becomes larger than 16000. You can safely use \tick directly (instead of \pgfmathresult).

While the last bit is certainly true, you can also use PGF’s math number printing facilities and change the style of the xticklabels with

xticklabel style={
    /pgf/number format/precision=3,
    /pgf/number format/zerofill,
},

which gives you the same output as siunitx\num macro.

code

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{filecontents*}{residuals_glycerin.txt}
-0.00106 328.43799 0.00092
-0.00038 328.18900 0.00092
0.00113 327.92099 0.00092
0.00057 327.70099 0.00092
0.00194 327.43600 0.00092
0.00246 327.19101 0.00092
-0.00389 327.10599 0.00092
0.00005 326.54800 0.00092
-0.00162 326.82001 0.00092
-0.00003 326.54999 0.00092
0.00057 326.30301 0.00092
0.00027 326.07700 0.00092
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xticklabel style={
        /pgf/number format/precision=3,
        /pgf/number format/zerofill,
    },
    scaled y ticks=false,
    xlabel={Resonant Magnetic Field [mT]},
    ylabel={Residuals [MHz]},
]
    \addplot[mark size=0.5, only marks, error bars/.cd, y dir=both, y explicit] table [y error index=2]         {residuals_glycerin.txt};
    \addplot[mark size=0.5, only marks, color=black]                            table [x index = 0, y index= 1] {residuals_glycerin.txt};
    \draw[ultra thick,red] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymin}) node[midway,above] {I'm a red line at $y = \pgfmathprintnumber{\pgfkeysvalueof{/pgfplots/ymin}}$.};
\end{axis}
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.