# Recreating a figure with Tikz

I want to recreate

Here is my MWE:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{minipage}{.35\textwidth}
\begin{tikzpicture}[scale=0.5]
\begin{axis}[
xmin=-.1,xmax=1.1,ymin=-.1,ymax=1.1,
axis lines=center,
ticks=none,
unit vector ratio*=1 1 1,
xlabel=$u$, ylabel=$v$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
]
\addplot [very thick, blue, smooth, domain=(-.2:.2+pi/2)] ({cos(deg(x))},{sin(deg(x))});
\addplot [black] plot coordinates {(0,0) (1,.839)}; %% 40 degrees
\addplot [very thick, blue] plot coordinates {(.766,0) (.766,.643)}; %% 40 degrees
\addplot [black] plot coordinates {(1,0) (1,.839)}; %% 40 degrees
\node at (axis cs:.15,.07) [anchor=west] {$x$};
\node at (axis cs:.766,.322) [anchor=east] {$\sin(x)$};
\node at (axis cs:.383,0) [anchor=north] {$\cos(x)$};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.35\textwidth}
\begin{tikzpicture}[scale=0.5]
\begin{axis}[
xmin=-.1,xmax=1.1,ymin=-.1,ymax=1.1,
axis lines=center,
ticks=none,
unit vector ratio*=1 1 1,
xlabel=$u$, ylabel=$v$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
]
\addplot [very thick, blue, smooth, domain=(-.2:.2+pi/2)] ({cos(deg(x))},{sin(deg(x))});
\addplot [black] plot coordinates {(0,0) (1,.839)}; %% 40 degrees
\addplot [black] plot coordinates {(.766,0) (.766,.643)}; %% 40 degrees
\addplot [black] plot coordinates {(1,0) (1,.839)}; %% 40 degrees
\addplot [very thick,blue] plot coordinates {(0,0) (.766,.643)}; %% sector
\addplot [very thick,blue] plot coordinates {(0,0) (1,0)}; %% sector
\addplot [very thick, blue, smooth, domain=(0:40)] ({cos(x)},{sin(x)}); %% sector
\node at (axis cs:.15,.07) [anchor=west] {$x$};
\node at (axis cs:.5,0) [anchor=north] {$1$};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.35\textwidth}
\begin{tikzpicture}[scale=0.5]
\begin{axis}[clip=false,
xmin=-.1,xmax=1.1,ymin=-.1,ymax=1.1,
axis lines=middle,
xlabel=$u$, ylabel=$v$,
ticks=none,
unit vector ratio*=1 1 1,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
]
\addplot [very thick, blue, smooth, domain=(-.1:1.671)] ({cos(deg(x))},{sin(deg(x))});
\addplot [very thick, blue] plot coordinates {(0,0) (1,.839)}; %% 40 degrees
\addplot [black] plot coordinates {(.766,0) (.766,.643)}; %% 40 degrees
\addplot [very thick, blue] plot coordinates {(1,0) (1,.839)}; %% 40 degrees
\node at (axis cs:.15,.07) [anchor=west] {$x$};
\node at (axis cs:.5,0) [anchor=north] {$1$};
\node at (axis cs:1,.42) [anchor=west] {$\tan(x)$};
\end{axis}
\end{tikzpicture}
\end{minipage}
\end{document}


My problem is with labels and shading.

• Have a look at the pgfmanual chapter 2 (Tutorial: A Picture for Karl’s Students). There you find all the information you need. – moospit Nov 9 '17 at 11:36

Unless you're adding \captions to each diagram, I don't think you need the minipages. In fact, you can make do with a single tikzpicture. While possible to do with three axis environments (you can set the position with at={<coordinate>}), the groupplot environment from the groupplots library is made for this type of thing.

It simplifies the code as you can set common settings for the axes just once. I also defined some styles for drawing, filling and nodes, and I defined a function A for the angle. All coordinates are then defined using cos(A)/sin(A)/tan(A), instead of the decimal values you had. This way you can easily change the angle as well -- modify the value for A and the whole diagram changes.

By the way, there are a couple of oddities in your code. The documented way of setting the domain is with domain=0:40, no parentheses (even though it actually works with them). And you're using \addplot plot coordinates, which is mixing the TikZ syntax \draw plot coordinates with pgfplots syntax \addplot coordinates. The plot keyword is not needed here.

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
% with compat=1.11 or higher, you don't have to specify "axis cs:" for coordinates in e.g. \node
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{groupplots}

\begin{document}
\begin{tikzpicture}[
% parameterise the angle
declare function={A=40;},
% for labels sin(x), cos(x), tan(x), 1
triglabels/.style={left,black,font=\footnotesize,inner sep=4pt},
% for outlines
blueline/.style={very thick, draw=blue},
% for filling
filling/.style={fill=blue!10},
% for Triangle A/B, Sector, below axes
caption/.style={below=2mm,font=\itshape}
]

\begin{groupplot}[
group style={
group size=3 by 1, % 3 columns in 1 row
horizontal sep=5mm,
group name=T % name used at the end
},
% the following settings apply to all three axes
xmin=-.1,xmax=1.1,
ymin=-.1,ymax=1.1,
axis lines=center,
ticks=none,
unit vector ratio*=1 1 1,
xlabel=$u$, ylabel=$v$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
% set default domain
domain=-.1:.1+pi/2,
% set clip=false to avoid clipping of nodes
clip=false,
]

\nextgroupplot
% draw arc

% draw tan(A) triangle
\addplot [black] coordinates {(0,0) (1,{tan(A)}) (1,0)};

% draw and fill triangle
\addplot [blueline,filling] coordinates {(0,0) ({cos(A)},0) ({cos(A)},{sin(A)}) (0,0)};
\node [triglabels,below] at ({cos(A)/2},0)        {$\cos(x)$};
\node [triglabels,left]  at ({cos(A)},{sin(A)/2}) {$\sin(x)$};

% angle
node[triglabels,right,midway] {$x$};

\nextgroupplot

% draw arc
\addplot [black] coordinates {(1,0) (1,{tan(A)}) (0,0)};

% do the filling in two steps, note \closedcycle
\addplot [filling] coordinates {(0,0) ({cos(A)},{sin(A)})} \closedcycle;

% draw the two sector lines, add "1"label along the way
\addplot [blueline] coordinates {({cos(A)},{sin(A)}) (0,0) (1,0)}
node[triglabels,below,pos=0.75] {$1$};
% then draw the arc

% angle
node[triglabels,right,midway] {$x$};

\nextgroupplot
% draw and fill triangle
\addplot [blueline,filling] coordinates {(0,0) (1,0) (1,{tan(A)}) (0,0)};
\node [triglabels,below] at (0.5,0) {$1$};
\node [triglabels,right] at (1,{tan(A)/2}) {$\tan(x)$};
% black line
% draw arc on top of filling

% angle
node[triglabels,right,midway] {$x$};

\end{groupplot}


• +1 Really nice! Where are c1r1, c3r1 and c3r1 defined? Perhaps they come for free from the groupplot? – Andrew Nov 9 '17 at 14:05
• @Andrew Yes, they come for free. With group name=T in the group style, the axes are automatically named T c<col num>r<row num>. – Torbjørn T. Nov 9 '17 at 14:09
• @TorbjørnT.: \pgfplotsset{compat=1.15} is creating an error. what should I do? – marya Nov 10 '17 at 8:10
• @marya Remove it altogether, set compat=newest to automatically select the most recent one available, or use \documentclass{standalone} \usepackage{pgfplots} \begin{document} \pgfplotsversion \end{document} to figure out which version of pgfplots you have, and use that version number. See tex.stackexchange.com/questions/81899 and tex.stackexchange.com/questions/139690 for some more about compat setting. – Torbjørn T. Nov 10 '17 at 8:23