Graphics, Figures & TablesTikz picture alignment two figures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Tikz picture alignment two figures

Post by coachbennett1981 »

I have been trying to figure this out. I have searched several places online and have seen several examples, but as for as figure alignment I am a novice. I need to have the two figures aligned in a way that the x-axis are at the same level. If you could help that would be great.

I have tried messing with my \myPlotB \draw location, but it does not work, I have tried minipage, but I keep getting errors.

Code: Select all

\documentclass[12pt]{article}
\usepackage[margin=.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns,angles,quotes,shadings,arrows.meta}

\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage{multicol}
\pgfplotsset{every x tick label/.append style={font=\footnotesize, yshift=0.6ex}}
\pgfplotsset{every y tick label/.append style={font=\footnotesize, xshift=0.5ex}}

\newcommand{\myplotB}[1]{
\begin{tikzpicture}
\draw[-Triangle] (-2,0)--(2,0);
\draw[Triangle-] (0,2)--(0,-2);
\node[below] at (2,0){$x$};
\node[above] at (0,2){$y$};
\node[below right] at (1,0){\footnotesize{1}};
\draw (0,0) circle [radius=1cm];
\end{tikzpicture}\hspace{.5in}
}

\begin{document}

\section*{Graphing Cosine Functions}
\noindent\rule{15cm}{0.4pt}

The function $y=A\cos t +k$ have \textbf{amplitude} $|A|$ and their \textbf{midline} is the horizontal line $y=k$


\begin{tikzpicture}
\begin{axis}[
grid style={blue!50},
axis x line = center,
axis y line = center,
xlabel style={above right},
ylabel style={above right},
xlabel={$x$}, ylabel={$y$},
xtick = {-1.5707, 0, ..., 6.28318},
xmin = -2,   xmax =6.28318,
ymin = -3,   ymax = 3,
ytick = {-3,-2,...,3},
xticklabels = {$-\frac{\pi}{2}$, 0, 
    $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$},
grid  = both,
]
\addplot[samples=300,domain=0:6.28318,color=red] {cos(deg(x))}; 
\filldraw[red] (0,1) circle (3pt) node at (0,1){};
\end{axis}
\end{tikzpicture}
\qquad
\myplotB

\end{document}

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Tikz picture alignment two figures

Post by Bartman »

My suggestion:

Code: Select all

\documentclass[12pt]{article}
\usepackage[margin=.5in]{geometry}
% It's enough to load a package once.
\usepackage{pgfplots}% loads tikz
    
\usetikzlibrary{arrows.meta}
     
\pgfplotsset{
    compat=1.17,
    every tick label/.append style={font=\footnotesize},
    every x tick label/.append style={yshift=0.6ex},
    every y tick label/.append style={xshift=0.5ex}
}
    
\newcommand{\myplotB}{
    \path 
        (current axis.right of origin) + (4,0) coordinate (origin plotB)
        (origin plotB) + (1,0) node [below right, font=\footnotesize] {1}
    ;
    \draw [-Triangle, at end]
        (origin plotB) + (-2,0) edge node [below] {$x$} + (2,0)
        (origin plotB) + (0,-2) edge node [above] {$y$} + (0,2)
        (origin plotB) circle [radius=1cm];
    ;
}
     
\begin{document}
\section*{Graphing Cosine Functions}
\rule{15cm}{0.4pt}
     
The function $y=A\cos t +k$ have \textbf{amplitude} $|A|$ and their 
\textbf{midline} is the horizontal line $y=k$
     
\begin{tikzpicture}
\begin{axis}[
    grid style={blue!50},
    axis lines = center,% reduced to one option
    label style={above right},
    xlabel={$x$}, ylabel={$y$},
    xtick = {-pi/2, 0, pi/2, pi, 3*pi/2, 2*pi},
    xmin = -2,   xmax = 2*pi,% number replaced by the multiple of the constant
    ymin = -3,   ymax = 3,
    ytick = {-3,-2,...,3},
    xticklabels = {$-\frac{\pi}{2}$, 0, 
        $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$},
    grid = both
]
\addplot[
    samples=300,
    domain=0:2*pi,% number replaced again
    color=red
] {cos(deg(x))};
\filldraw[red] (0,1) circle (3pt);
\end{axis}
\myplotB
\end{tikzpicture}
\end{document}
Graphing_Cosine_Functions.png
Graphing_Cosine_Functions.png (19.56 KiB) Viewed 5453 times
If you're open for some other formatting for the x-axis tick labels, you may be interested in Stefan Pinnow's solution.
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Tikz picture alignment two figures

Post by coachbennett1981 »

Thank you so much for your suggestion
Post Reply