2

I'm having trouble drawing some functions:

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage[normalem]{ulem} 
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
        \begin{axis}[grid=major,ymax=2500,xmax=2500]
          \addplot[no markers, blue, restrict y to domain=0:1714, samples=30000] { 2412 - 2.795e-10*(x^4)};
        \end{axis}
\end{tikzpicture}

\end{document}

Code runs through fine but there's no function appearing, only the coordinate system and grid.

Works fine now! -> see below.

What doesn't work is this function:

    \documentclass{scrartcl}
\usepackage{amsmath}
\usepackage[normalem]{ulem} 
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}



\begin{tikzpicture}
        \begin{axis}[grid=major,ymax=10000,xmax=10000,xmin=0,ymin=0]
          \addplot[no markers, blue, domain=0:10000, samples=10, % you can make it larger 
          %restrict y to domain=0:1714,% but this filter the results anyway
          samples=300 
          ] { 93231-3.552e-10*x^5};
        \end{axis}
\end{tikzpicture}


\end{document}

enter image description here

2

Your code samples should produce the following error messages:

Package pgfplots Warning: the current plot has no coordinates (or all have been filtered away) on input line 11.

Package pgfplots Warning: You have an axis with empty range (in direction y). Replacing it with a default range and clearing all plots. on input line 12.

So pgfplots actually informs you about the empty plotting range. You can fix this by providing a domain range of x values to be plotted.

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage[normalem]{ulem} 
\usepackage{tikz} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}
        \begin{axis}[grid=major,ymax=2500,xmax=2500]
          \addplot[no markers, blue, domain=1200:1800, % you can make it larger 
          restrict y to domain=0:1714,% but this filter the results anyway
          samples=300 % I reduced the number of samples to speed-up the compilation
          ] { 2412 - 2.795e-10*(x^4)};
        \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Also in your second example you are filtering to a y range, so that no points are left to be plotted.

\begin{tikzpicture}
        \begin{axis}[grid=major,ymax=100000,xmax=10000,xmin=0,ymin=0]
          \addplot[no markers, blue, domain=0:1000, %s
          restrict y to domain=0:100000,% 
          samples=301 
          ] { 93231-3.552e-10*x^5};
        \end{axis}
\end{tikzpicture}
2
  • Works like a charm, thank you. So in the end is was just the samples? I have another function, that doesn't work. I edited my question. – SF6 Mar 16 '17 at 7:56
  • @SF6 I updated my answer with your second example. Feel free to accept it ;-) – hakaze Mar 17 '17 at 20:13

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.