I prefer the look of the second graph but want the functionality of the first. That is, define the equation by its name rather then transforming points.
How can I extend the axis outside the boxed area in the first graph to look more like the second graph.
\documentclass[12pt,addpoints]{exam}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds}
\pgfplotsset{every axis/.append style={
axis x line=middle,
axis y line=middle,
axis line style={<->},
xlabel={$x$},
ylabel={$y$},
line width=1pt,}}
% line style
\pgfplotsset{cmhplot/.style={color=black,mark=none,<->}}
% arrow style
\tikzset{>=stealth}
% framing the graph
\tikzset{tight background}
\begin{document}
\begin{tikzpicture}
\begin{axis}[framed,
xmin=-10,xmax=10,
ymin=-10,ymax=10,
xtick={-8,-6,...,8},
xticklabels={,,,,,,,,},
ytick={-8,-6,...,8},
yticklabels={,,,,,,,,},
grid=both]
\addplot[cmhplot]expression[domain=-9.5:9.5,samples=50]{x};
\end{axis}
\end{tikzpicture} \\
\begin{tikzpicture}[scale=.3]
\begin{scope}
\clip (-10,-10) rectangle (10,10);
\draw[step=2cm,gray,very thin]
(-12,-12) grid (10,10);
\end{scope}
\draw [<->] (-11,0) -- (11,0);
\draw [<->](0,-11) -- (0,11);
%\clip (-10,-10) rectangle (10,10);
\end{tikzpicture}
\end{document}
Best Answer
Extend Axis Past Grid:
I am not sure if there is a pre defined way to have different limits on the grid, but you could certainly add a grid separately as desired. For instance, with
you get:
Code:
Extend Graph Past Grid:
To extend the graph beyond the grid you can limit the the min/max x and y values to be less than your graph and add the option
clip=false
:Code: