# Draw axis in block diagram

I would like to add plots inside TikZ nodes. Here is a minimum working example of the code I already have.

\documentclass[]{standalone}
\usepackage{pgf,tikz,pgfplots}
\usetikzlibrary{calc,positioning}
\pgfplotsset{compat=1.15}

\begin{document}
\begin{tikzpicture}
\draw node[draw,minimum width=2cm, minimum height=15mm},label=Test] {};
\begin{scope}[x=0.016cm,y=8,shift={(-0.8cm,0cm)}]
\draw[thick] (0,0) plot[domain=0:100,samples=30,mark=none] ({\x},{sin(2*pi*\x)});
\end{scope}
\end{tikzpicture}
\end{document}


The MWE creates the following figure:

I would like to use multiple of these nodes in a block diagram. Is it possible to replace the scope with a regular axis with axis lines and a fixed width and height to simply replace the plot with a different one without affecting the appearance of the axis?

Modified version, a frame is drawn as part of the simple axis style, and an argument to that style lets you specify a name for the frame node. Positioning can be done relative to other nodes with the calc library, but not using the convenient syntax of the positioning library (as far as I know).

\documentclass[border=5mm]{standalone}
\usetikzlibrary{calc,fit}
\pgfplotsset{
compat=1.15,
simple axis/.style={
scale only axis,
anchor=center,
axis lines=middle,
enlargelimits=0.1,
width=2cm,
height=15mm,
xtick=\empty,
ytick=\empty,
domain=0:100,
tickwidth=0,
clip mode=individual,
every axis plot/.append style={smooth},
cycle list={
black, thick\\
black, thick, dashed \\
},
before end axis/.code={
\node [draw,fit=(current axis)] (#1) {};
}
},
simple axis/.default=foo
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ % no position defined, so this ends up at (0,0)
simple axis=ax1,
title=Test,
]

\end{axis}

\begin{axis}[
simple axis=ax2,
title=Test2,
at={($(ax1.east)+(1cm,0)$)}, % specify position relative to east anchor of ax1
anchor=west
]
\end{axis}

\draw [red, thick, -stealth] (ax1) -- (ax2);

\end{tikzpicture}
\end{document}


Are you after something like this?

\documentclass[border=5mm]{standalone}
\usetikzlibrary{calc,positioning}
\pgfplotsset{
compat=1.15,
simple axis/.style={
scale only axis,
width=2cm,
height=15mm,
xtick=\empty,
ytick=\empty,
domain=0:100,
tickwidth=0
}
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ % no position defined, so this ends up at (0,0)
simple axis,
title=Test,
]
\end{axis}

\begin{axis}[
simple axis,
title=Test2,
at={(3cm,1cm)} % specify position
]
\end{axis}
\end{tikzpicture}
\end{document}

• This almost looks perfect, thank you. Is it possible to add these axis inside the nodes, so I can simply make a block diagram out of it? I would also like to have the arrows for the axis lines as well as the box around it.
– brnk
Jun 17 '19 at 15:35
• @brnk I updated my answer a bit, perhaps some of the modifications are of interest. Jun 17 '19 at 16:51

I was able to change Torbjørn T's solution by myself. I changed the axis' anchor to center and placed it at the node's position.

\documentclass[border=5mm]{standalone}
\usetikzlibrary{calc,positioning}
\pgfplotsset{
compat=1.15,
simple axis/.style={
scale only axis,
width=1.7cm,
height=12mm,
xtick=\empty,
ytick=\empty,
domain=0:100,
tickwidth=0,
axis lines=left,
enlargelimits=upper,
anchor=center,
}
}

\begin{document}
\begin{tikzpicture}
\draw node[draw,minimum width=2cm, minimum height=15mm,label=Test] (node1) {};
\begin{axis}[simple axis,at={(node1)}]