Welcome to our community

Be a part of something great, join today!

TiKZ axis labels

dwsmith

Well-known member
Feb 1, 2012
1,673
I am trying to label the y axis with pi and -pi. How can I do that?

Code:
\begin{tikzpicture}
\draw[->] (0,0) -- (3.5,0) coordinate (x axis);
\draw[->] (0,-3.5) -- (0,3.5) coordinate (y axis);
\end{tikzpicture}
 

Evgeny.Makarov

Well-known member
MHB Math Scholar
Jan 30, 2012
2,493
I am trying to label the y axis with pi and -pi. How can I do that?
Do you mean to draw ticks and labels at (0, $\pi$) and (0, $-\pi$)? You could do the following.

Code:
\def\npi{3.1416}
\begin{tikzpicture}
\draw[->] (0,0) -- (3.5,0) node[below] {$x$};
\draw[->] (0,-3.5) -- (0,3.5) node[left] {$y$};
\draw (2pt,\npi) -- (-2pt,\npi) node {$\pi$};
\draw (2pt,-\npi) -- (-2pt,-\npi) node {$-\pi$};
\end{tikzpicture}
I have not tested this code, but I hope it is right.
 

Sudharaka

Well-known member
MHB Math Helper
Feb 5, 2012
1,621
I am trying to label the y axis with pi and -pi. How can I do that?

Code:
\begin{tikzpicture}
\draw[->] (0,0) -- (3.5,0) coordinate (x axis);
\draw[->] (0,-3.5) -- (0,3.5) coordinate (y axis);
\end{tikzpicture}
Hi dwsmith, :)

With some experimenting I found that the following code works. :) Note that I have inserted the blue part to your code.

Code:
\begin{tikzpicture} [COLOR=#0000ff]

%ticks[/COLOR]
[COLOR=#0000ff]\foreach \y/\ytext in {-3.14/-\pi,3.14/\pi}[/COLOR]
[COLOR=#0000ff]\draw (1pt,\y) -- (-3pt,\y) [/COLOR]
[COLOR=#0000ff]node[anchor=east] {$\ytext$}; [/COLOR]
[COLOR=#0000ff]%[/COLOR]

\draw[->] (0,0) -- (3.5,0) coordinate (x axis);
\draw[->] (0,-3.5) -- (0,3.5) coordinate (y axis);

\end{tikzpicture}
>>Here<< is a useful resource that you can find examples of these kind of things. :)

Kind Regards,
Sudharaka.