I would like to produce a graph like I attached.enter image description here

I started with drawing a coordinate system and adding 3 points, to create a triangle, but the reference is not the origin of the coordinate system... How could I get the attached graph?

  %Same unit length
  axis equal,
  transform shape,
  axis lines=middle,
  axis line style={Stealth-Stealth, thick},
  xtick distance=1,
  ytick distance=1,
  grid style={line width=.1pt, draw=darkgray!10},
  major grid style={line width=.2pt,draw=darkgray!50},
  axis lines=middle,
  %For plot of functions domain
  domain = -8:8

\addplot[blue] {-1/2*x} node[above,pos=1] {};
\addplot[red] {2*x} node[above,pos=1] {};

\draw (10,8) node[anchor=north] {a}
  -- (13,8) node[anchor=north]{b}
  -- (18,14) node[anchor=south]{c}
  -- cycle;

  • 2
    You seem to be using packages pgfplots and tkz-euclide. Please edit your post to provide a "Minimal Working Example" (MWE) that starts with \documentclass, includes all relevant \usepackage commands, ends with \end{document} and compiles without errors, even if it does not produce your desired output.
    – Sandy G
    Mar 20 at 17:48
  • I would not use pgfplots for a graph like that but everything is possible. I think you should between plain TikZ and pgfplots.
    – SebGlav
    Mar 20 at 18:14
  • 1
    I'm guessing you could add \pgfplotsset{compat=1.11} to the preamble. By default coordinates used for \draw, \path, \node inside the axis environment of pgfplots is not given in the coordinates of the axis. To explicitly use the axis coordinate system, use axis cs: as a prefix in the coordinate, e.e. \draw (axis cs:0,0) .... With compat=1.11 or higher on the other hand, axis cs: becomes the default, so it's not necessary to explicitly add it to the coordinates. Mar 20 at 19:15

1 Answer 1


Since you seem to not know anything about TikZ yet, here's a simple solution without any fancy tricks, with straightforward commands that you may learn from. Note that this is not the best way to do that but one may start with something simple.

graph in TikZ


        \draw[gray!50,very thin] (-5,-4) grid (5,4);
        \draw[thick,-latex] (-5,0) -- (5,0) node [below left] {x};
        \draw[thick,-latex] (0,-4) -- (0,4) node [below left] {y};
        \foreach \x in {-4,...,-1,1,2,3,4} \draw (\x,2pt) --++ (0,-4pt) node [below] {\x};
        \foreach \y in {-3,...,-1,1,2,3} \draw (2pt,\y) --++ (-4pt,0) node [left] {\y};

        \fill[cyan, fill opacity=0.5] (0,0) -- (0,2) node [right, pos=0.6, red, opacity=1] {$\Delta$x} -- (-1,2) node [above, pos=0.5, blue, opacity=1] {$\Delta$y} -- cycle;
        \fill[violet, fill opacity=0.5] (0,0) -- (2,0) node [below, pos=0.75, red, opacity=1] {$\Delta$x} -- (2,1) node [right, pos=0.5, blue, opacity=1] {$\Delta$y} -- cycle;
        \fill[red, fill opacity=0.5] (0,0) -- (-153:0.8) arc(-153:-63:0.8) node[pos=0.5, above] {90$^{\circ}$} -- cycle;
            \clip (-5,-4) rectangle (5,4);  
            \draw[line width=1pt,olive,domain=(-5:5)] plot (\x,-2*\x);
            \node[olive, above] at (-1.4,3) {g};
            \draw[line width=1pt,blue!50!cyan,domain=(-5:5)] plot (\x,0.5*\x);      
            \node[blue!50!cyan, above left] at (4,2) {f};

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.