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.
        \begin{tikzpicture}[baseline={([yshift=-1em] current bounding box.north)}]
            \begin{axis}
            [
                x = 0.75cm,
                y = 0.75cm,
                xlabel = $x$,
                ylabel = $y$,
                xmin = -10,
                xmax = 10,
                restrict x to domain = -10:10,
                ymin = -10,
                ymax = 10,
                restrict y to domain = -10:10,
                axis x line = middle,
                axis y line = middle,
            ]
                \addplot {x};
                \legend{$y = x$};
            \end{axis}
        \end{tikzpicture}

fail

Why does the graph only render from (-5,-5) to (5,5)? It should be (-10,-10) to (10,10)

share|improve this question
1  
By default domain=-5:5 I think. –  Torbjørn T. Apr 10 at 19:48
    
Wow you were right. What is the purpose of setting the x and y domains separately then? –  No_name Apr 10 at 19:50
    
restrict to domain does not set the domains directly. What they do is to filter out values above or below the given interval. I'll add an answer in a bit. –  Torbjørn T. Apr 10 at 20:02

1 Answer 1

up vote 5 down vote accepted

The restrict <x/y> to domain keys does not set the domain used for calculating y values, that is done by the domain key. The default value for domain is -5:5, meaning that functions are evaluated for -5 <= x <= 5.

Here is a quote from pgfplots' manual about the restrict keys:

These keys append x (or y or z) coordinate filters to restrict the respective coordinate to a domain. The versions without star (like restrict x to domain) will assign the value -inf if the coordinate is below min and +inf if the coordinate is above max . The starred versions (like restrict x to domain*) will truncate coordinates to [min, max], i.e. they assign the value min if the coordinate falls outside of the lower limit and max if the value falls outside of the upper limit.

The example from the manual has the plot of tan(x) over several cycles.

\documentclass[tikz,border=5mm]{standalone}
\usepackage{pgfplots}    
\begin{document}    
\begin{tikzpicture}
\begin{axis}[
restrict y to domain=-10:10,
samples=1000,
% some fine-tuning for the display:
width=10cm, height=210pt,
xmin=-4.7124, xmax=4.7124,
xtick={-4.7124,-1.5708,...,10},
xticklabels={$-\frac32 \pi$,$-\pi/2$,$\pi/2$,$\frac32 \pi$},
axis x line=center,
axis y line=center]
\addplot[blue] gnuplot[id=tangens,domain=-1.5*pi:1.5*pi]{tan(x)};

\legend{$\tan(x)$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Hence, for your example the restrict ... keys are not really needed, and to get the plot for -10 < x 10, add domain=-10:10:

\documentclass[tikz,border=5mm,convert={false,density=100}]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[baseline={([yshift=-1em] current bounding box.north)}]
    \begin{axis}
    [
     x = 0.75cm,
     y = 0.75cm,
     xlabel = $x$,
     ylabel = $y$,
     xmin = -10,
     xmax = 10,
     ymin = -10,
     ymax = 10,
     domain=-10:10,
     axis lines = middle,
    ]
\addplot {x};
\legend{$y = x$};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
So to get this straight, "domain" is for setting the range of x values to input into the function, "restrict x/y to domain" is for discarding output values from the function that exceed it, and "x/ymin/max" are limits for the drawing of the grid itself? –  No_name Apr 10 at 20:27
    
@No_name That sounds about right, yes. –  Torbjørn T. Apr 10 at 20:38

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.