2

I need two or three distinct coordinate systems in "one tikz environment". The systems are very similar (some linear functions, some labels, the same axis scale). A horizontal shift or minipage are not sufficient, because I also need to add some cross-connections between these graphs (which it pretty economic). Those "things betweens the graphs" are often just lines (see picture).

Here is some code which at least "looks like" the thing I want to achieve:

\documentclass{article}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[axis lines=middle,xmin=-0.5,xmax=10.5,ymin=-0.5,ymax=33]
        \addplot+[no marks,domain=0:6,samples=200, thick] {x+2};    
  \end{axis}
    \hspace{8cm}
  \begin{axis}[axis lines=middle,xmin=-0.5,xmax=10.5,ymin=-0.5,ymax=33]
        \addplot+[no marks,domain=0:6,samples=200, thick] {x+4};    
  \end{axis}
\end{tikzpicture}

\end{document}

Just for illustration I manually added a horizontal line to highlight different intercepts of the two lines. This is of cause a very simplistic MWE of what I need to create at the end. Thank you very much.

enter image description here

2

You can have multiple axes, which can be shifted (don't use \hspace here), and you can define coordinates or nodes within them, which you can connect.

\documentclass{article}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[axis lines=middle,xmin=-0.5,xmax=10.5,ymin=-0.5,ymax=33]
        \addplot+[no marks,domain=0:6,samples=200, thick] {x+2};    
        \coordinate (X1) at (0,2);
  \end{axis}

  \begin{axis}[xshift=8cm,axis lines=middle,xmin=-0.5,xmax=10.5,ymin=-0.5,ymax=33]
        \addplot+[no marks,domain=0:6,samples=200, thick] {x+4}; 
        \coordinate (X2) at (3.5,2); 
  \end{axis}
        \draw[very thick] (X1) -- (X2);  
\end{tikzpicture}

\end{document}

enter image description here

  • Thank you so much, that's too obvious, I didn't thought of it. – Marco Feb 27 at 14:42
  • 2
    @Marco If marmot's answer helps you, you should upvote and accept (by clicking the tick) his answer. Accepting is the best "thank you" on SE. – user156344 Feb 27 at 15:00
  • Well, I tried. But the time limit (7 min?) hasn't passed for the acceptance and I havn't had enough credits to upvote. I've done both right now :) – Marco Feb 27 at 15:31
  • @marmot One more question, I use scaling for the entire picture \begin{tikzpicture}[scale=1.4] this scales everything within my axis-environment, but does not adjust the additional lines, that is to say, it results in a vertical shift of \draw[very thick] (X1) -- (X2); How can I circumvent this? – Marco Feb 27 at 16:08
  • @Marco Yes, if you do too many of the transformations there will always be a situation in which pgfplots does not catch up with them, see also tex.stackexchange.com/a/463789/121799. I am not saying scale=1.4 is too much. pgfplots is being continuously updated, and you are using an older version (but switching to the newer version only does not fix this here). For the moment, you could do \scalebox{1.4}{\begin{tikzpicture} ... \end{tikzpicture}}. – user121799 Feb 27 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.