# Comparison of the plots of the same line on the Cartesian plane using pgfplots and TikZ [closed]

I have the plot of a line using pgfplots and the plot of the same line using TikZ. I would like them to be identical.

I need to correct a mistake in the plot of a line using pgfplots. The point that is plotted should be at the point (a, ma+b). Since a=-3 and m=-0.5=b, the point as specified in the code is (-3,-2). Why is the point not plotted correctly?

In the plot of a line using TikZ, I need to put the label "y = mx + b" in the right place. (Look at the other plot.) I also need to add two tick marks - one on the x-axis at -3 and one on the y-axis at -2. I was told that there was a default option for tick marks. (I was not able to view the datavisualization library as described in chapter 75 of the manual at the following web site: texdoc.net/texmf-dist/doc/generic/pgf/pgfmanual.pdf .)

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{mathtools}

\usepackage{pgfplots}

\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
axis lines=middle,
xmin=-5,xmax=5,samples=201,
xlabel=$x$,ylabel=$y$,
ymin=-3.5,ymax=2.5,
restrict y to domain=-3.5:2.5,
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={\empty},
extra x ticks={-3},
extra x tick labels={$a$},
extra y ticks={-2},
extra y tick labels={$ma+b$},
yticklabel style={anchor=west},
yticklabel shift=-4pt,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=201,domain=-5:5,blue] {0.5*x - 0.5} node[above left, pos=0.9,font=\footnotesize]{$y = mx + b$};
\end{axis}
\end{tikzpicture}
\hspace*{\fill}
\vskip0.25in

\noindent \hspace*{\fill}
\begin{tikzpicture}
\draw[draw=gray!30,latex-latex] (0,2.5) +(0,0.5cm) node[above right] {$y$} -- (0,-3.5) -- +(0,-0.5cm);
\draw[draw=gray!30,latex-latex] (-5,0) +(-0.5cm,0) -- (5,0) -- +(0.5cm,0) node[below right] {$x$};
\draw[blue,domain=-5:5,samples=2,latex-latex] plot (\x, 0.5*\x - 0.5) node[above left, pos=0.9,font=\footnotesize]{$y = mx + b$};
\end{tikzpicture}
\hspace*{\fill}
\vskip0.25in

\end{document}


## closed as off-topic by Stefan Pinnow, Zarko, Mensch, user36296, Arun DebrayJun 15 '17 at 21:37

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• When you use normal TikZ commands like \draw inside an axis environment, you should either use the axis cs: coordinate system (so \draw [fill] (axis cs:-3,-2) circle [radius=1.5pt];), or set \pgfplotsset{compat=1.11} (or newer), which activates the axis cs coordinate system. – Jake Feb 26 '15 at 17:32
• I think you can't place nodes on a plot using the pos syntax in plain TikZ, you'll need to either move it manually or draw the plot using a normal path. Just out of curiosity: why do you need to find two ways of achieving the same output? – Jake Feb 26 '15 at 19:54
• No, you don't. That's what I meant in my first comment, either use axis cs or compat=1.11. Then you said "I added compat=1.11", then you asked me again how to put the dot in the right place, so I assumed that for some reason that approach didn't work for you. – Jake Feb 27 '15 at 20:13
• By "normal path", I meant using \draw[blue,latex-latex] (-5,-3) -- (5,2) node[above left, pos=0.9,font=\footnotesize]{$y = mx + b$}; instead of \draw[blue,domain=-5:5,samples=2,latex-latex] plot (\x, 0.5*\x - 0.5) node[above left, pos=0.9,font=\footnotesize]{$y = mx + b$}; (so using the -- syntax instead of plot). The datavisualization library is described in chapter 75 of TikZ version 3.0. You're probably using 2.1? – Jake Mar 5 '15 at 18:19
• I'm voting to close this question because it is solved in the comments. – Stefan Pinnow Jun 15 '17 at 20:00