# Plotted line in tikz stops in middle of grid

The plotted line stops and doesn't go on till the border of the grid: This is my code:

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[baseline={(current bounding box.north)}]
\draw[step=1cm,color=gray!20] (-3,-2) grid (6,6);
\draw[-] (-3,0) -- (6,0) node[right] {$x$};
\draw (0,0) node[below left] {$O$};
\draw[-] (0,-2) -- (0,6) node[above] {$y$};
\foreach \x in {-3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {-2, -1, 1, 2, 3, 4, 5, 6}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\draw[blue] (-2,4) node[below left] {$k$};
\draw[black] (4,5) node[above left] {$A$};
\clip (-3,-2) rectangle (6,6);
\draw[scale=1,smooth,variable=\x,blue] plot ({\x},{(-4/3)*\x});
\draw[scale=1,smooth,variable=\x,red] plot ({\x},{(3/4)*\x+2});
\draw[fill=black](4,5) circle(0.5mm);
\end{tikzpicture}

\end{document}


What can I do so the line goes on the border of the grid?

• Add domain=-3:6 to the last draw should work. Actually both can use the same range. – Jesse Nov 27 '14 at 3:52

Use domain=-4:7;

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[baseline={(current bounding box.north)}]
\draw[step=1cm,color=gray!20] (-3,-2) grid (6,6);
\draw[-] (-3,0) -- (6,0) node[right] {$x$};
\draw (0,0) node[below left] {$O$};
\draw[-] (0,-2) -- (0,6) node[above] {$y$};
\foreach \x in {-3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {-2, -1, 1, 2, 3, 4, 5, 6}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\draw[blue] (-2,4) node[below left] {$k$};
\draw[black] (4,5) node[above left] {$A$};
\clip (-3,-2) rectangle (6,6);
\draw[scale=1,smooth,variable=\x,blue] plot ({\x},{(-4/3)*\x});
\draw[scale=1,smooth,variable=\x,red,domain=-4:6] plot ({\x},{(3/4)*\x+2});
\draw[fill=black](4,5) circle(0.5mm);
\end{tikzpicture}
\end{document}


Graphs a better done with pgfplots: ## Notes:

• The axis cs: is only needed if this is to be produced with versions priot to 1.11. So adding \pgfplotsset{compat=1.11} and using a recent version of pgfplots you don't need the axis cs:.

## Code:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}

%% http://tex.stackexchange.com/questions/17438/how-to-properly-scale-a-tikz-pgf-picture-which-has-a-beginaxis-endaxis
\pgfkeys{/pgfplots/Axis Labels At Tip/.style={
xlabel style={
at={(current axis.right of origin)},
xshift=1.5ex, anchor=center
},
ylabel style={
at={(current axis.above origin)},
yshift=1.5ex, anchor=center
}
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
x=1cm, y=1cm,% Better to let pgfplots do this, added in case it is important
axis y line=center,
axis x line=center,
xmin=-3, xmax=6,
ymin=-2, ymax=6,
grid=major,
Axis Labels At Tip,
xlabel=$x$, ylabel=$y$,
]
\addplot [red,  thick, domain=-3:6] {(3/4)*x + 2};

\node [below left, blue] at (axis cs: -2,4) {$k$};
\node [below left] at (axis cs: 0,0) {$O$};
\draw[fill=black]  (axis cs: 4,5) circle(0.5mm)
node[above left] at (axis cs: 4,5) {$A$};
\end{axis}
\end{tikzpicture}
\end{document}


## Code: \pgfplotsset{compat=1.11}

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}

\pgfplotsset{compat=1.11}

%% http://tex.stackexchange.com/questions/17438/how-to-properly-scale-a-tikz-pgf-picture-which-has-a-beginaxis-endaxis
\pgfkeys{/pgfplots/Axis Labels At Tip/.style={
xlabel style={
at={(current axis.right of origin)},
xshift=1.5ex, anchor=center
},
ylabel style={
at={(current axis.above origin)},
yshift=1.5ex, anchor=center
}
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
x=1cm, y=1cm,% Better to let pgfplots do this, added in case it is important
axis y line=center,
axis x line=center,
xmin=-3, xmax=6,
ymin=-2, ymax=6,
grid=major,
Axis Labels At Tip,
xlabel=$x$, ylabel=$y$,
]
\addplot [red,  thick, domain=-3:6] {(3/4)*x + 2};

\node [below left, blue] at (-2,4) {$k$};
\node [below left] at (0,0) {$O$};
\draw[fill=black]  (4,5) circle(0.5mm)
node[above left] at (4,5) {$A$};
\end{axis}
\end{tikzpicture}
\end{document}


A PSTricks solution using the pst-plot package:

\documentclass{article}

\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-3.2,-2.1)(6.65,6.7)
\psaxes[
labels = none,
tickcolor = black!30,
tickwidth = 0.5pt,
xticksize = -2 6,
yticksize = -3 6
]{->}(0,0)(-3,-2)(6.3,6.3)[$x$,0][$y$,90]
\psaxes{->}(0,0)(-3,-2)(6.3,6.3)[$x$,0][$y$,90]
\uput(0,0){$O$}
\psset{algebraic}
\psplot[
linecolor = blue
]{-3}{1.5}{-4/3*x}
\rput(-2.37,3.63){$\color{blue}k$}
\psplot[
linecolor = red
]{-3}{5.333}{3/4*x+2}
\psdot(4,5)
\uput[126.87](4,5){$A$}
\end{pspicture}

\end{document} 