Labeling Y-Axis with Pi and -Pi

  • Context: MHB 
  • Thread starter Thread starter Dustinsfl
  • Start date Start date
  • Tags Tags
    Pi
Click For Summary
SUMMARY

This discussion focuses on labeling the y-axis with π and -π using TikZ in LaTeX. A user sought assistance on how to implement these labels, and another participant provided a solution involving the use of a foreach loop to create ticks and labels at the coordinates (0, π) and (0, -π). The final code snippet shared successfully demonstrates how to achieve this labeling in a TikZ picture environment.

PREREQUISITES
  • Familiarity with LaTeX document preparation system
  • Understanding of TikZ package for creating graphics
  • Basic knowledge of coordinate systems in graphing
  • Experience with LaTeX syntax for mathematical symbols
NEXT STEPS
  • Explore TikZ documentation for advanced graphing techniques
  • Learn how to customize axis labels in LaTeX
  • Investigate the use of foreach loops in TikZ for repetitive tasks
  • Study examples of mathematical typesetting in LaTeX
USEFUL FOR

LaTeX users, mathematicians, educators, and anyone interested in creating professional-quality graphs and diagrams using TikZ.

Dustinsfl
Messages
2,217
Reaction score
5
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}
 
Physics news on Phys.org
dwsmith said:
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.
 
dwsmith said:
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} 

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

\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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
6
Views
2K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K