Graphics, Figures & Tablespgfplots | Cosecant Function Graph

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

pgfplots | Cosecant Function Graph

Post by sachinrajsharma »

Hi,

I am facing trouble in output of this code for a plot.

Code: Select all

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      xmin=-6,xmax=6,
      ymin=-2,ymax=2,
      axis x line=middle,
      axis y line=middle,
      axis line style=<->,
      xlabel={$x$},
      ylabel={$y$},
    ]
      \addplot[no marks,blue,<->] expression[samples=100]{cosec(deg(x} node[pos=3.0,anchor=south east]{$y=\cosec(x)$}; 
    \end{axis}
  \end{tikzpicture}
\end{document}
I get an error.

Code: Select all

! Undefined control sequence.
Please help in rectifying this issue.


Regards,
Sachin Sharma

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Cosecant Function Graph

Post by localghost »

There are two mistakes in your code.
  1. Two parentheses are missing in the actual plot command.
  2. The \cosec command does not exist. But \csc does.
The corrected example.

Code: Select all

\documentclass[11pt]{standalone}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      xmin=-6,
      xmax=6,
      xlabel={$x$},
      ymin=-2,
      ymax=2,
      ylabel={$y$},
      axis x line=middle,
      axis y line=middle,
      axis line style=<->
    ]
      \addplot[no marks,blue,<->] expression[samples=100]{cosec(deg(x))};
      \addlegendentry{$y=\csc(x)$}; 
    \end{axis}
  \end{tikzpicture}
\end{document}

Thorsten
sachinrajsharma
Posts: 35
Joined: Sun Apr 08, 2012 5:48 am

Re: pgfplots | Cosecant Function Graph

Post by sachinrajsharma »

Thanks a lot....its great...

Sachin
Post Reply