# Tangent plot on tikz [closed]

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{amsmath,amssymb}
\usepackage{tikz}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}[scale=1.2,smooth,domain=-2*pi:2*pi];
% First line looks reasonable
\draw[blue = solid,  thick ] plot   [domain=0:5*pi/12](\x,{tan(\x r)});
% second line is not goo
\draw[blue = solid,  thick ] plot    [domain=27*pi/45:17*pi/12](\x,{tan(\x r)});

\draw[blue = solid,  thick ] plot   [domain=1.6*pi:29*pi/12](\x,{tan(\x r)});

\end{tikzpicture}
\caption{Graph of $y = \tan\theta$}
\label{fig:graphtan}
\end{center}
\end{figure}

-

## closed as not a real question by clemens, percusse, Jake, cmhughes, Marco DanielAug 23 '12 at 5:50

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

The plots look fine to me. Would you mind explaining in more detail what you mean by "second line is not good"? It's best to attach a screenshot of the output you get. –  Jake Aug 22 '12 at 9:04
Traditionally, downvotes on this site are reserved for questions that are unsalvageable or spam. This is not the case here, so I think it would be good not to downvote this. Furthermore, downvotes on non-spam questions should always be accompanied by a comment explaining the motivation behind the downvote, and what can be done to improve the question. If a question is improved sufficiently after a downvote, please remember to undo the downvote. –  Jake Aug 22 '12 at 9:50
@Jake From the FAQ: "Use your downvotes whenever you encounter an egregiously sloppy, no-effort-expended post". To me, this question meets that criteria as it is nothing more than a code block, and one without a ? at that. In the future I will comment, but here, the asker has been a member for 7 months and has the analytical badge so I assumed that he knew why his question might have received a downvote. I will happily undo it if the post is improved. –  Scott H. Aug 22 '12 at 10:49
@ScottH.: I absolutely agree with you, and the FAQ indeed calls for relatively liberal use of downvotes. However, I feel that on this particular Stackexchange site, we're much more sparing with downvotes than on others, which makes the downvotes more powerful ("Wow, -1, that must be a truly horrible question") and it gives the site a more welcoming and forgiving atmosphere. –  Jake Aug 22 '12 at 11:55
+1 for the nice question! –  kiss my armpit Aug 22 '12 at 14:57

The following is PSTricks' solution. Just for fun!

## Features

The feature I propose here is that you can determine the dimension of diagram in advance. For example, the total width must be 10 cm and its height must be 4 cm. You can also specify offsets to make the border, labels, and arrows have enough spaces and balanced.

## User Interface

\def\f(#1){tan(#1)}% function to plot
\def\g[#1]{cos(#1)}% function to plot
\def\h#1{sin(#1)}% function to plot

\const{Width}{10}% total width in cm
\const{Height}{4}% total height in cm

\const{POL}{-0.20}% pspicture left offset in cm
\const{POR}{ 0.50}% pspicture right offset in cm
\const{POB}{-0.20}% pspicture bottom offset in cm
\const{POT}{ 0.50}% pspicture top offset in cm

\const{AOL}{-0.20}% axis left offset in cm
\const{AOR}{ 0.30}% axis right offset in cm
\const{AOB}{-0.20}% axis bottom offset in cm
\const{AOT}{ 0.30}% axis top offset in cm

\const{DomL}{-2*pi}% domain left
\const{DomR}{2*pi}% domain right
\const{DomB}{-2}% domain bottom
\const{DomT}{ 2}% domain top

\const[0]{TrigLabelBase}{2}% denominator for a fraction of pi


## User Interface Explanation

Note that the following diagram uses different values to provide spaces for annotations. If you are trying to map the values described above to the corresponding annotations below, then you are comparing orange with banana!

## Complete Code

\documentclass[border=0pt,pstricks]{standalone}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{\expandafter\FPeval\csname#2\endcsname{round(#3:#1)}}

% User defined data:
\def\f(#1){tan(#1)}% function to plot
\def\g[#1]{cos(#1)}% function to plot
\def\h#1{sin(#1)}% function to plot

\const{Width}{10}% total width in cm
\const{Height}{4}% total height in cm

\const{POL}{-0.20}% pspicture left offset in cm
\const{POR}{ 0.50}% pspicture right offset in cm
\const{POB}{-0.20}% pspicture bottom offset in cm
\const{POT}{ 0.50}% pspicture top offset in cm

\const{AOL}{-0.20}% axis left offset in cm
\const{AOR}{ 0.30}% axis right offset in cm
\const{AOB}{-0.20}% axis bottom offset in cm
\const{AOT}{ 0.30}% axis top offset in cm

\const{DomL}{-2*pi}% domain left
\const{DomR}{2*pi}% domain right
\const{DomB}{-2}% domain bottom
\const{DomT}{ 2}% domain top

\const[0]{TrigLabelBase}{2}% denominator for a fraction of pi

% Internal used constants:
\const{XUnit}{(Width-POR+POL-AOR+AOL)/(DomR-DomL)}
\const{YUnit}{(Height-POT+POB-AOT+AOB)/(DomT-DomB)}

\const{PicL}{(POL+AOL)/XUnit+DomL}
\const{PicR}{(POR+AOR)/XUnit+DomR}
\const{PicB}{(POB+AOB)/YUnit+DomB}
\const{PicT}{(POT+AOT)/YUnit+DomT}

\const{AxiL}{AOL/XUnit+DomL}
\const{AxiR}{AOR/XUnit+DomR}
\const{AxiB}{AOB/YUnit+DomB}
\const{AxiT}{AOT/YUnit+DomT}

\const{DeltaX}{pi/TrigLabelBase}

\psset{xunit=\XUnit,yunit=\YUnit,algebraic,plotpoints=500}

\begin{document}

\begin{pspicture}[showgrid=false](\PicL,\PicB)(\PicR,\PicT)
\psplot[linecolor=red,yMaxValue=\AxiT,yMinValue=\AxiB]{\DomL}{\DomR}{\f(x)}
%    \psplot[linecolor=green]{\DomL}{\DomR}{\g[x]}
%    \psplot[linecolor=blue]{\DomL}{\DomR}{\h{x}}
\psaxes
[
trigLabels=true,
labelFontSize=\scriptscriptstyle,
tickcolor=gray,
ticksize=-1.5pt 1.5pt,
xlabelsep=3pt,
arrowscale=1,
trigLabelBase=\TrigLabelBase,
dx=\DeltaX,% must come before xunit to avoid getting a strange output!
]{->}(0,0)(\AxiL,\AxiB)(\AxiR,\AxiT)[$x$,0][$y$,90]
\end{pspicture}

\end{document}


## Notes

Compile the code with latex->dvips->ps2pdf.

-

run with xelatex or latex->dvips->ps2pdf

\documentclass[a4paper,12pt]{article}
\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-5.5,-7)(6.5,6.5)
\psaxes[trigLabelBase=2,dx=\psPiH,
xunit=\psPi,trigLabels]{->}(0,0)(-1.7,-5.5)(1.77,5.5)[$x$,0][$y$,90]
\psplot[algebraic,yMaxValue=5,linewidth=1.6pt,plotpoints=2000,
linecolor=red]{-4.55}{4.55}{tan(x)}
\psline[linestyle=dashed](-\psPiH,-5)(-\psPiH,5)
\psline[linestyle=dashed](\psPiH,-5)(\psPiH,5)
\end{pspicture}

\end{document}


-
Here is my messed pdf file from tikz. /Users/lim/Desktop/messy_tangent_plot.tiff –  mark Aug 23 '12 at 2:54
I am not set up properly for pstricks and don't understand how it works. –  mark Aug 23 '12 at 3:00