I would like to have the picture look like the hand drawing.Help would be greatly appreciated, thank you. The graph of Tangent

  • you can use metapost, geogebra or texgraph – touhami Mar 14 '15 at 18:04
  • I should have specified that I am trying to do it using tikz-pgf – TuoTuo Mar 14 '15 at 18:43
  • with geogebra or texgraph you can convert to tikz – touhami Mar 14 '15 at 18:50
  • see tex.stackexchange.com/questions/74878/… – touhami Mar 14 '15 at 19:02
  • 3
    Please show us, what have you tried that isn't working? Most times, people don't like to answer questions that feel like "Do this thing for me", instead prefer to answer questions that are more like "I'm stuck with this small aspect, how can I accomplish it?" – darthbith Mar 14 '15 at 20:18

With pgfplots


    extra x ticks={-1.5708, 1.5708},
    extra x tick labels={$-\frac{\pi}{2}$, $\frac{\pi}{2}$},
    every extra x tick/.style={
            xticklabel style={anchor=north west},
            major grid style={thick,dashed,red}
    axis lines = center,
        \addplot [red,thick] {tan(deg(x))};

enter image description here

| improve this answer | |

If you wish to give its chance to MetaPost, here is an example, included in a LuaLaTeX program, of what it can do with your problem:

\documentclass[12pt, border=1bp]{standalone}
\usepackage{amsmath, luamplib}
vardef function(expr xmin, xmax, xstep)(text f_x) =
    save x; x := xmin;
    (x, f_x) forever:
        hide(x := x + xstep)
        exitif x > xmax;
        .. (x, f_x) 
    if x - xstep < xmax: hide(x := xmax) .. (x, f_x) fi
numeric u, xmin, xmax, Xmin, Xmax, xstep, ymin, ymax;
u = 1.5cm; Xmax = -Xmin = 2.25; Ymax = -Ymin = 4.75; xstep = 0.05; xmax = -xmin = 1.5;

    draw function(xmin, xmax, xstep)(tan x) scaled u;
    clip currentpicture to 
        ((Xmin, Ymin) -- (Xmax, Ymin) -- (Xmax, Ymax) -- (Xmin, Ymax) -- cycle) scaled u;
    draw u*(-pi/2, Ymin) -- u*(-pi/2, Ymax) dashed evenly;
    draw u*(pi/2, Ymin) -- u*(pi/2, Ymax) dashed evenly;
    drawarrow u*(Xmin, 0) -- u*(Xmax, 0);
    drawarrow u*(0, Ymin) -- u*(0, Ymax);
    label.bot("$x$", (Xmax*u, 0)); label.lft("$y$", (0, Ymax*u)); 
    label.ulft("$O$", origin);
    label.llft("$-\dfrac{\pi}{2}$", (-u*pi/2, 0)); 
    label.llft("$\dfrac{\pi}{2}$", (u*pi/2, 0));
    labeloffset := 6bp;
    for i = -4 upto 4: 
        if i<>0: 
            draw (-3bp, i*u) -- (3bp, i*u); label.lft("$" & decimal i & "$", (0, i*u)); 

enter image description here

| improve this answer | |
  • this does'nt answer the question. – touhami Mar 14 '15 at 20:19
  • 4
    @touhami Strictly speaking, yes it does: ‘‘I would like to have the picture look like the hand drawing. Help would be greatly appreciated, thank you.’’ I know my solution does not use the OP's required package, but in general people here appreciate as well to see how the same drawing can be done with other graphical solutions. It can also help to improve the solutions given with the desired package, by emulation. What is really missing here is an example of coding given by the OP's, even rudimentary, showing how he had first tackled the problem… – Franck Pastor Mar 14 '15 at 20:46
  • 3
    @touhami: As fpast said, it's generally accepted (and encouraged) to post answers that use different approaches or packages than what is requested by the asker (see meta.tex.stackexchange.com/questions/3408/…). In a way, answers aren't just for the benefit of the asker, but for the general community, and it's definitely instructive to see different approaches for achieving the same outcome. – Jake Mar 14 '15 at 21:19
  • @fpast and jake (+1) you are right and the answer is welcom. I wanted to direct your attention to the question may have missed something (excuse my bad english) – touhami Mar 14 '15 at 21:57

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.