2

I'm trying to plot this simple graph resembling the graph below

Example plot

So far I've figured out how to graph some basics using the below but don't know how to plot coordinate and y-intercept along with the line

\documentclass[fleqn]{article}
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{mathexam}
\usepackage{amsmath}
\usepackage{pgfplots}

\ExamHead{\today}

\let\ds\displaystyle

\begin{document}
\ExamInstrBox{
Please show \textbf{all} your work! Answers without supporting work will not be marked. Write answers in spaces provided. You have 1 hour to complete this exam.}
\ExamNameLine
\begin{enumerate}
   \item Find the equation of these lines
    \begin{enumerate}
       \item \begin{tikzpicture}
            \begin{axis}[xlabel = x, ylabel = y, axis lines=center, axis on top=true]
            \addplot [mark=none,draw=black,ultra thick] {1/2*x+3};
            \end{axis}
            \end{tikzpicture}
            \answer
        \item \begin{tikzpicture}
            \begin{axis}[xlabel = x, ylabel = y, axis lines=center, axis on top=true]
            \addplot [mark=none,draw=black,ultra thick] {3*x-1};
            \end{axis}
            \end{tikzpicture}
            \answer

    \end{enumerate}
\end{enumerate}
\end{document}
  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – N3buchadnezzar Feb 7 at 12:49
  • @N3buchadnezzar thank you for your input. I've updated the question now. – buffoonUser Feb 8 at 1:13
2

A bit modified @PeterGrill answer (+1):

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    axis lines=middle, axis on top,
    xlabel = $x$, ylabel = $y$,
    x label style={anchor=west},
    y label style={anchor=south},
    axis equal,
    xtick=\empty,   ytick=\empty,           % <---
    extra x ticks=0,
    x tick label style={anchor=north east}, % <---
    xmin=-3.5, xmax=5.5,                    % <---
    ymin=-0.5, ymax=5.5,                    % <---
            ]
\addplot [red,domain=-3:5,very thick, <->] {1/2*x+3};
\addplot [only marks] coordinates {(4,1/2*4+3)} node[above left] {(2,4)};
\addplot [only marks] coordinates {(0,1/2*0+3)} node[above left] {(0,3)};
\end{axis}
    \end{tikzpicture}
\end{document}
| improve this answer | |
2

You can use a \addplot coordinates to place a point at the desired point:

\addplot [draw=none, mark=*] coordinates{(4,5)} node [left] {(4,5)};

enter image description here

Notes

  • Also, the axis labels should be in math mode. I have modified those in the MWE below.

Code:

\documentclass[fleqn]{article}
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{mathexam}
\usepackage{amsmath}
\usepackage{pgfplots}
\pagecolor{white}

\ExamHead{\today}

\let\ds\displaystyle

\begin{document}
\ExamInstrBox{
Please show \textbf{all} your work! Answers without supporting work will not be marked. Write answers in spaces provided. You have 1 hour to complete this exam.}
\ExamNameLine
\begin{enumerate}
   \item Find the equation of these lines
    \begin{enumerate}
       \item \begin{tikzpicture}
            \begin{axis}[xlabel = $x$, ylabel = $y$, axis lines=center, axis on top=true]
            \addplot [mark=none,draw=black,ultra thick] {1/2*x+3};
            \addplot [draw=none, mark=*] coordinates{(4,5)}
                node [above left] {(4,5)};
            \end{axis}
            \end{tikzpicture}
            \answer
        \item \begin{tikzpicture}
            \begin{axis}[xlabel = $x$, ylabel = $y$, axis lines=center, axis on top=true]
            \addplot [mark=none,draw=black,ultra thick] {3*x-1};
            \end{axis}
            \end{tikzpicture}
            \answer

    \end{enumerate}
\end{enumerate}
\end{document}
| improve this answer | |

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.