1

I have a beamer frame inside which I want to include a figure composed of 3 independent plots, like this:

3 plots

Please note that each one of these has completely different axis domain and unit vector ratio*. So, if I am not wrong, groupplot is not suitable for this situation.

I created the following .tikz file:

% myPlot.tikz
\begin{tikzpicture}
\begin{axis}[domain=-5:5,unit vector ratio*=2 1]
\addplot {x};
\end{axis}
\begin{scope}[yshift=-7cm]
\begin{axis}[domain=-1:3,unit vector ratio*=1 2]
\addplot {-x};
\end{axis}
\end{scope}
\begin{scope}[yshift=-7cm,xshift=8cm]
\begin{axis}[domain=-2:10,y domain=0:4,unit vector ratio*=1 0.8]
\addplot {x*x};
\end{axis}
\end{scope}
\end{tikzpicture}

And inside my beamer frame I have

% main.tex
\documentclass[dvipsnames]{beamer}
\usepackage{tikz,pgfplots,graphicx,siunitx,tikzscale}
\pgfplotsset{compat=1.17}
\usepackage{geometry,xcolor}    
\geometry{paperwidth=148mm,paperheight=96mm}
\useoutertheme[width=20mm]{sidebar}
\usecolortheme{beaver}
\begin{document}
\begin{frame}{Algebra and Geometry}
\begin{figure}
\includegraphics[width=\textwidth,height=230pt]{myPlot.tikz}
\end{figure}
An additional line of text.
\end{frame}
\end{document}

But I get an error

! Dimension too large.
<recently read> \pgfmath@x 

What is the correct way of creating such figure?

I am really having hard time at it, and would really like to solve this issue soon.

Desired output is

enter image description here

(Made artificially with Windows Paint)

I also tried

\resizebox{\textwidth}{194pt}
{
\input{myPlot.tikz}
}

Bit it stretches the figure:

not good

Needless to say, the real figure I am working on is composed of 3 much more complicated axis environments, one of which is a surf and the other is a curve in the 3d space..

I guess that the problem starts with the scope environment that I defined that calls for a an x and y shift specified in cm's.

I think that the best way is to let TeX decide what should be xshift and yshift, and to be calculated according to the figure width and height inside includegraphics.

This where I am asking for you help.

Update:

I just learned that one can do

% myPlot.tikz
\begin{tikzpicture}
\pgfplotsset{width=\textwidth,height=194pt}

\begin{axis}[domain=-5:5,unit vector ratio*=2 1] % rest of file.. \end{tikzpicture}

But still I shifted the begin{axis} in the x and y direction, by some values in cm, after a few trial and errors, until I got a satisfactory output.

I wonder if there is a better solution.

tush
  • 1,115
  • Considering what you say at the end there, I'd consider using three separate tikzpictures, defining an appropriate size for each axis, e.g. width=\linewidth, height=0.3\linewidth for the first one, without involving tikzscale. – Torbjørn T. Jun 15 '21 at 17:44

1 Answers1

1

Instead of manual shifts, you can add a name to the first axis, and place the other two axes using the available anchors described in section 4.19 Alignment options of the pgfplots manual (page 374 in manual for version 1.18.1).

The -| notation is a way to get the x-position of one coordinate, and the y-position of another, cf. TikZ: What EXACTLY does the the |- notation for arrows do?

\documentclass[dvipsnames]{beamer}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage{geometry}    
\geometry{paperwidth=148mm,paperheight=96mm}
\useoutertheme[width=20mm]{sidebar}
\usecolortheme{beaver}
\begin{document}
\begin{frame}{Algebra and Geometry}

\begin{tikzpicture} \begin{axis}[ unit vector ratio*=2 1, width=0.5\linewidth, name=topaxis] \addplot {x}; \end{axis}

\begin{axis}[ domain=-1:3,unit vector ratio*=1 2, height=0.4\linewidth, at={(topaxis.south west |- topaxis.outer south west)}, anchor=north west, ] \addplot {-x}; \end{axis}

\begin{axis}[ domain=-2:10,y domain=0:4,unit vector ratio=1 0.8, height=0.4\linewidth, at={(topaxis.south east |- topaxis.outer south east)}, anchor=north east] \addplot {xx}; \end{axis}

\end{tikzpicture}

An additional line of text. \end{frame} \end{document}

Torbjørn T.
  • 206,688